1

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?

Rella
  • 65,003
  • 109
  • 363
  • 636
  • Why should a constant be private? It's already save from manipulation by being a constant. I don't think it's necessary to hide it completely in any scenario. – selfawaresoup Jun 18 '10 at 14:13

1 Answers1

2

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.

Artefacto
  • 96,375
  • 17
  • 202
  • 225
  • and will const SIGNATURE1 = 0x46; be avaliable for bites like operations? (see my next Question http://stackoverflow.com/questions/3070298/what-is-php-for-c-readbytesstream-langth ) – Rella Jun 18 '10 at 14:11
  • @Ole Jak Yes, you can do stuff like `999 & MyClass::SIGNATURE1`. – Artefacto Jun 18 '10 at 14:14