Warning: 1 argument is missing

Any idea why I am getting 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 also use this in my index file:

 $tyler = new person("Tyler"); 
+6
constructor php warnings
source share
5 answers

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

+11
source share
 $persons_name = "" 

Set it as in the argument. But this is not a solution. You can delete the construct, create a new instance, and then set the name. If your somehow does not work.

+4
source share

You call the constructor without passing an argument. Perhaps you are doing something like $p = new person(); instead of $p = new person("theirName");

+2
source share

It seems: If the class name matches the function name, this warning is provided. If you call the function differently from the class name, it seems OK. You need to specify the arguments only when calling the function not in the class instance

0
source share

Try this code

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

initialized internal construction method NULL.

0
source share

All Articles