Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP equivalent to Ruby symbol

Does PHP have symbols like Ruby? Or, should I just use strings as the keys in a PHP associative array?

I'm guessing it's the same answer as that of the question Is there a Python equivalent to Ruby symbols?

like image 900
ma11hew28 Avatar asked Mar 17 '11 21:03

ma11hew28


2 Answers

PHP has definable constants, but that's not really very useful in this context.

So no. Use strings as keys.

like image 109
Matthew Avatar answered Oct 05 '22 23:10

Matthew


If your concern is the overload of using strings as array keys and the fact that the array is copied instead of passed as reference every time, I can suggest you to use stdClass, that is basically an object class that can be modified dynamically, array-like, but it behaves as an object.

like image 42
Zequez Avatar answered Oct 06 '22 00:10

Zequez