Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: Missing 1 argument

Any idea why I get this error:

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

With this code:

<?
    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;
            }

    }
?>

I'm also using this in my index file:

$tyler = new person("Tyler");
like image 944
Phil Avatar asked Dec 23 '10 16:12

Phil


2 Answers

When instantiated you did: $obj = new person(); instead of $obj = new person("joe");

like image 108
Babiker Avatar answered Sep 28 '22 00:09

Babiker


$persons_name = ""

Set it like this in argument. But that is not solution. You can remove construct, make new instance and then set name. If yours somehow doesn't work.

like image 27
Dejan Marjanović Avatar answered Sep 28 '22 00:09

Dejan Marjanović