PHP class variable assignment problem
phpcn_u1582
phpcn_u1582 2017-05-16 13:03:21
0
4
444

< /p>

As shown in the figure
I want to know why class variables cannot be assigned to object method variables
but it can be done in the constructor

phpcn_u1582
phpcn_u1582

reply all(4)
小葫芦

The variable members of a class are called "properties", or "fields" or "features", and are collectively referred to as "properties" in this document. A property declaration starts with the keywords public, protected or private, and is followed by an ordinary variable declaration.

Variables in attributes can be initialized, but the initialized value must be a constant. The constant here means that the PHP script can get its value during the compilation phase and does not rely on runtime information to evaluate.

http://php.net/manual/zh/lang...

左手右手慢动作

It’s not that class variables cannot be assigned variables, but that this variable cannot be dynamic: such as the result of a method, such as a certain operation.

PHPzhong

Because this is the syntax of PHP...

Peter_Zhu

The value in a class variable can only be a specific value, a number, a string or an array
It cannot be a class method

This is a grammatical rule, just remember it, there is no reason why

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template