Search code examples
c#phpconstantsbyteprivate

how to create in PHP analog of C# ' private const int ' and ' private const byte '?


So in C# I create something like

    private const int HEADER_LENGTH = 13;
    private const byte SIGNATURE1 = 0x46;

How to create its analog in PHP?


Solution

  • No. The closest things are:

    const HEADER_LENGTH = 13;
    

    which is not private and

    private static $HEADER_LENGTH = 13;
    

    which is not final. You cannot also constrict the type of the variable. There is also no 1-byte type in PHP – you should use an integer for that or a string with length 1.

    You can implement something like that internally by overriding the get_property_ptr_ptr and write_property object handlers, but not with only PHP.