Home >Backend Development >PHP Tutorial >Unable to call parameters in __construct
Asking for advice.
Asking for advice.
Let me take the liberty of guessing the poster’s intention:
<code>class Man{ private $_name; private $_age; public function __construct($name, $age) { $this->_name = $name; $this->_age = $age; } public function getName() { return $this->_name; } }</code>
@paul5 You have not assigned a value to _age
or _name
, so of course it will be empty when you take it out. It seems that your code only assigns values to name
and age
, and there are fewer underscores?
Construct is $this->name;
getName is $this->_name;
Forgot to underline