PHP Superclass constructor

I have just found this expression in some PHP code I wrote around two years ago:

// Call the constructor of the parent class

$this->{get_parent_class(CLASS)}();

I've never seen this syntax before, and I couldn't find any reference to it in the PHP documentation. The closest I found was a brief mention that curly brackets could be used to resolve ambiguity in expressions like ${$a}[0]. I have probably pasted it from somewhere after taking a dislike to some of the other ways of calling the superclass constructor (which must be done explicitly in PHP).

This looks like it might be useful in a variety of situations, except that I'm reluctant to use what is, AFAICT, undocumented syntax.

Comments

Comments powered by Disqus