note 83125 modified in language.oop5.reflection by danbrown

From: Date: Wed, 16 Sep 2009 16:13:06 +0000
Subject: note 83125 modified in language.oop5.reflection by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160712@lists.php.net to get a copy of this message
The note about the signature of the ReflectionParameter constructor is actually incomplete, at least in 5.2.5: it is possible to use an integer for the second parameter, and the constructor will use it to return the n-th parameter. This allows you to obtain proper ReflectionParameter objects even when documenting code from extensions which (strangely enough) define several parameters with the same name. The string-based constructor always returns the first parameter with the matching name, whereas the integer-based constructor correctly returns the n-th parameter. So, in short, this works: <?php // supposing the extension defined something like: // Some_Class::someMethod($a, $x, $y, $x, $y) $p = new ReflectionParameter(array('Some_Class', 'someMethod'), 4); // returns the last parameter, whereas $p = new ReflectionParameter(array('Some_Class', 'someMethod'), 'y'); // always returns the first $y at position 2 ?> --was-- The note about the signature of the ReflectionParameter constructor is actually incomplete, at least in 5.2.5: it is possible to use an integer for the second parameter, and the constructor will use it to return the n-th parameter. This allows you to obtain proper ReflectionParameter objects even when documenting code from extensions which (strangely enough) define several parameters with the same name. The string-based constructor always returns the first parameter with the matching name, whereas the integer-based constructor correctly returns the n-th parameter. So, in short, this works: <?php // supposing the extension defined something like: // Some_Class::someMethod($a, $x, $y, $x, $y) $p = new ReflectionParameter(array('Some_Class', 'someMethod'), 4); // returns the last parameter, whereas $p = new ReflectionParameter(array('Some_Class', 'someMethod'), 'y'); // always returns the first $y at position 2 ?> http://php.net/manual/en/language.oop5.reflection.php

« previous php.notes (#160712) next »