Acessing class constants dynamically

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

The mere notion that the constant() function is useless or bad practice is utterly ridiculous and unfounded.
Did you read my post? I didn't say it was useless.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Ree wrote:
jmut wrote: You guys really amaze me. The problem is so simple and yet you make it look so complicated. I'm really trying to figure out what you're so confused about that it 'smells' or 'looks weird' to you. You don't seem to think dynamic method invocation is wrong, but using constants the same way is? Again, that would be ridiculous IMO.
Welcome to the php world. ;) Ever thought why "foo()['bar']" doesn't work in php? Or "$klass::foo()"? Or "empty(foo())"? Just because someone in php team once said it "looks weird" and "smells".
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Just because someone in php team once said it "looks weird" and "smells".
I would hazard a guess that the reason for most of those is because of the way PHP is written. empty() for example is a language construct and runs very quickly because no function call is necessary but this has limitations. That said I would really like...

Code: Select all

foo()['bar']
..to work...

Code: Select all

list('bar' => $bar) = foo()
...would be acceptable.
Post Reply