< /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
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.
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