Hacker News new | ask | show | jobs
by mccutchen 5468 days 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.

1 comments

Just 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.