Unable to call parameters in __construct

WBOY
Release: 2016-07-06 13:51:19
Original
1328 people have browsed it

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>
Copy after login

@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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template