Class - variable declaration

oop, php

Solution

You cannot use statement or function, just a scalar value. This is because class variables are initiated in compile time (before runtime). Class constructor should be used to initiate property with statement/function.

Problem

When the declaration of a PHP class variable we cannot perform any expressions, e.g.: ``` class A { $a = 10 + 5; } ``` only we can just provide constants e.g.: ``` class A { $a = 100; } ``` Can anybody knows why its like that?

Original source