6 ms·
"and how 'reflection' is way simpler than any other language" I've never heard this claim made, and it has been a long time since I've actually used PHP in any
by mccutchen 15y ago
"and how 'reflection' is way simpler than any other language"
I've never heard this claim made, and it has been a long time since I've actually used PHP in any meaningful way. Care to expand on this?
I'd be interested in a comparison to Python's support for reflection, which is simple and pervasive.
- glassx 15y agoJust a disclaimer: I have zero work experience with PHP, just personal experience. I put it inside quotation marks because it's not the true-reflection API per se, but I believe it was a mistake to even bring that up, and to generalize by saying it's easier than 'any other language'. I was talking about old methods like get_class_methods, get_class_vars, get_object_vars and $$. Here's an example which I used to answer another user above: $a = new A; foreach(get_object_vars($a) as $name => $var) { $a->$name = $a->$name + 1; echo $a->$name . "\n"; } By no means those things are absolutely "beautiful", but they get the job done and they're one-liners, hence, simple. They're simpler than Java and C#, languages which I worked for years. Also they're easier than Ruby sometimes. To be honest, I just think it is fun. I can make things in PHP with five lines that would take me multiple pages in C#, but the opposite is true too, for other areas.