php - 警告 : Missing 1 argument

标签 php constructor warnings

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

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 = new person("joe");

关于php - 警告 : Missing 1 argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4520605/

相关文章:

class - PowerShell中的构造函数链接-调用同一类中的其他构造函数

c++ - C++中构造函数的奇怪使用

perl - 如何简洁地检查警告类别直至包中层次结构的根部?

c - "control reaches end of non-void function"是什么意思?

php - imagettftext() : Could not find/open font error message

php - 删除数组中的重复值

Php MySql 日期之间的生日查询忽略年份

php - MySQL PHP 锁表,在期望并发连接时有没有更好的解决方案

Javascript寄生构造函数似乎无法向对象添加函数,为什么

php - homebrew -- Image Magick 在执行 PHP 时抛出版本错误