The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Reflection and extending PHP internal classes

Submitted by nk on Sun, 2012-07-01 20:42

Two weeks ago I posted two brain teasers about extending ReflectionClass. Let's see the results -- after the break so people not having fun with them yet can.

So you have

class Psr0ClassReflector extends ReflectionClass {
__construct($x) {

$x = new Psr0ClassReflector('foobar broken class name');

and we are curious what happens. Two people guessed E_STRICT error -- that is very unlikely, E_STRICT means this has a meaningful result just PHP really does not like the syntax, the way of calling or somesuch. Another two guessed "Just segfaults because the internal structure isn't there" now come on, PHP is not that crappy. The four who guessed string(24) "foobar broken class name" really intrigues me -- just how on earth could the object persist that string? Ten altogether guessed some error (notice 4, warning 4, fatal 2) -- these are the rational guesses. The seven who correctly guessed string(0) "" IMO cheated because there is no rhyme or reason this should not error out. ReflectionClass keeps the name passed to the internal constructor in the name property and also an internal structure based on this. This is mentioned in a manual comment. Why on earth would the name property be initialized to anything at all? Finally, if you were among the four who guessed Something totally else I would like you to tell us what did you think will happen.

Now comes the really interesting twist, running var_dump($x->getFileName());. What happens? Let me tell you first: this fatals out because the internal structure is not there. There were a lot less results and they were evenly distributed so it's a lot less fun. However, "The name of the file this code is in" is another very illogical answer. The rest has some reasoning behind them.

Commenting on this Story is closed.

Submitted by Anonymous on Tue, 2012-07-31 18:39.

Nice to find some good content for once, I am getting sick of the continual drivel I come across recently, thank you.