Home >Backend Development >PHP Tutorial >Unable to call parameters in __construct

Unable to call parameters in __construct

WBOY
WBOYOriginal
2016-07-06 13:51:191368browse

Unable to call parameters in __construct

Unable to call parameters in __construct

Asking for advice.

Reply content:

Unable to call parameters in __construct

Unable to call parameters in __construct

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn