Do public static final class variables exist

php

Solution

From this page in the PHP manual:

Note: Properties cannot be declared final, only classes and methods may be declared as final.

However, you can use class constants as described here.

Your example would look something like this:

<?php

class MyClass{
    const finalVariable = "something";
}

MyClass::finalVariable;
?>

Except of course that `finalVariable` isn't really an appropriate name because it's not variable =).

Problem

In Jave you can define a `public static final` variable in a class. Is there an equivalent to this in PHP? I'd like to do the following: ``` <?php class MyClass{ public final static $finalVariable = "something"; } MyClass::$finalVariable ``` and not ever have to worry about `$finalVariable` changing and not having a new instance for every instantiation of `MyClass`

Original source

Related problems