php – 警告:缺少1个参数

知道我为什么会收到这个错误:

Warning: Missing argument 1 for person::__construct(), called in /home/fishbein/public_html/dev/OOP/index.php on line 5 and defined in /home/fishbein/public_html/dev/OOP/class_lib.php on line 6

Warning: Missing argument 1 for person::__construct(), called in /home/fishbein/public_html/dev/OOP/index.php on line 6 and defined in /home/fishbein/public_html/dev/OOP/class_lib.php on line 6

使用此代码:

<?
    class person {

            var $name;

            function __construct($persons_name) {       
            $this->name = $persons_name;        
            }

            function set_name($new_name) {
                $this->name = $new_name;
            }

            function get_name() {
                return $this->name;
            }

    }
?>

我也在我的索引文件中使用它:

$tyler = new person("Tyler");
最佳答案
实例化时你做了:$obj = new person();而不是$obj =新人(“乔”);

转载注明原文:php – 警告:缺少1个参数 - 代码日志