$s = new Person();This bracket reports an error
在学php了
在学php了 2022-07-15 17:04:35
0
9
845
为什么这个括号会报错呀

dc4ee2ae65a848eac1d54849c8806c0.png

在学php了
在学php了

reply all(2)
autoload
$variable = '李四';
$s = new Person($variable);

That’s it

  • reply Isn't it possible to create a new instance without initializing it?
    在学php了 author 2022-07-15 17:27:48
  • reply I copied a piece of code on csdn, and an error was reported in my own parentheses. I was puzzled for a long time.
    在学php了 author 2022-07-15 17:29:10
  • reply https://blog.csdn.net/weixin_34152820/article/details/91883654?ops_request_misc=%7B%22request%5Fid%22%3A%22165787695116782184680934%22%2C%22scm%22%3A%2220140713.13 0102334..%22%7D&request_id =165787695116782184680934&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-91883654-null-null.142^v32^pc_search_v2,185^v2^control&utm_term=php access control&spm= 1018.2226. 3001.4187 This is this article, he created an uninitialized instance
    在学php了 author 2022-07-15 17:30:01
  • reply Take a look at the reply below. It’s preset in the constructor, so it must be there. Just don’t preset it.
    autoload author 2022-07-16 15:40:56
  • reply His new one is Student, not Person, you can see clearly for yourself
    autoload author 2022-07-16 15:42:40
  • reply Yes, there was something wrong with the parentheses when I was a new student. It was like this at first, but I found it after I posted this question. Public function __construct($name="") can be solved in this way. I just want to know if $s = new Student(); is wrong in not initializing this example.
    在学php了 author 2022-07-18 09:05:57
autoload

image.png

The constructor has formal parameters, and when creating a new object, it takes actual parameters

  • reply Public function __construct($name="") will do it
    在学php了 author 2022-07-15 17:26:25
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template