I just read about
Top Bad Practices in PHP and became curious if what I’m doing is also a bad practice…
I usually typecast an array to object
$person = (object)$person;
just because I prefer typing
$person->name
than
$person['name']
Note: I’m not dealing with multi-dimensional arrays when I use this approach.
Need expert advice so I can stop if this is a bad practice 🙁 Thanks Guys!
No, it’s not bad practice. As a matter of fact, it’s even on the PHP page as a published example: http://www.php.net/manual/en/language.types.object.php#language.types.object.casting
There are plenty of legitimate uses, also (your example is a bit capricious); for example:
is faster than