note 103955 modified in reflectionclass.getconstructor by danbrown

From: Date: Fri, 13 May 2011 15:37:22 +0000
Subject: note 103955 modified in reflectionclass.getconstructor by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179699@lists.php.net to get a copy of this message
Old constructors also count as contructor: <?php class SomeClass { function SomeClass($some_arg) { } } $refl = new ReflectionClass('SomeClass'); var_dump($refl->isInstantiable()); // bool(true) echo $refl->getConstructor(); /* OUTPUT: Method [ <user, ctor> public method SomeClass ] { @@ /var/www/vhosts/api.example.com/httpdocs/testRefl.php 5 - 6 - Parameters [1] { Parameter #0 [ <required> $some_arg ] } } */ ?> Some more behavior: <?php class SomeClass { function funcA($arg1, $arg2) { } } $refl = new ReflectionClass('SomeClass'); var_dump($refl->isInstantiable()); // bool(true) var_dump($refl->getConstructor()); // NULL /* --------------- */ class AnotherClass { private function __construct() { } function funcB($arg1, $arg2) { } } $refl = new ReflectionClass('AnotherClass'); var_dump($refl->isInstantiable()); // bool(false) echo $refl->getConstructor(); /* Method [ <user, ctor> private method __construct ] { @@ /testRefl.php 22 - 23 } */ ?> Tested on PHP 5.2.4 --was-- Old constructors also count as contructor: <?php class SomeClass { function SomeClass($some_arg) { } } $refl = new ReflectionClass('SomeClass'); var_dump($refl->isInstantiable()); // bool(true) echo $refl->getConstructor(); /* OUTPUT: Method [ <user, ctor> public method SomeClass ] { @@ /var/www/vhosts/api.example.com/httpdocs/testRefl.php 5 - 6 - Parameters [1] { Parameter #0 [ <required> $some_arg ] } } */ ?> Tested on PHP 5.2.4 http://php.net/manual/en/reflectionclass.getconstructor.php

« previous php.notes (#179699) next »