I'd like to assign the result of a count
over a constant to a constant. Here is an example of what I am trying to achieve:
class A
{
private $a = count('Hello'); # PHP Fatal error: Constant expression contains invalid operations
}
$a = new A();
echo $a->a;
The working equivalent in C++:
#include <iostream>
class A
{
public:
const int a = sizeof("Hello");
};
int main(void)
{
A a = A();
std::cout << a.a << std::endl;
return 0;
}
Is there any way to achieve this in PHP without using a constructor or calling a method from outside the class ?