Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

jochem at drecomm dot nl
15 years ago
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

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /