--- /dev/null
+--TEST--
+ReflectionObject::getFileName(), ReflectionObject::getStartLine(), ReflectionObject::getEndLine() - basic function
+--FILE--
+<?php
+$rc = new ReflectionObject(new C);
+var_dump($rc->getFileName());
+var_dump($rc->getStartLine());
+var_dump($rc->getEndLine());
+
+$rc = new ReflectionObject(new stdclass);
+var_dump($rc->getFileName());
+var_dump($rc->getStartLine());
+var_dump($rc->getEndLine());
+
+Class C {
+
+}
+?>
+--EXPECTF--
+string(%d) "%sreflectionObject_FileInfo_basic.php"
+int(12)
+int(14)
+bool(false)
+bool(false)
+bool(false)
+--UEXPECTF--
+unicode(%d) "%sreflectionObject_FileInfo_basic.php"
+int(12)
+int(14)
+bool(false)
+bool(false)
+bool(false)
--- /dev/null
+--TEST--
+ReflectionObject::getFileName(), ReflectionObject::getStartLine(), ReflectionObject::getEndLine() -invalid aparams
+--FILE--
+<?php
+Class C { }
+
+$rc = new ReflectionObject(new C);
+$methods = array("getFileName", "getStartLine", "getEndLine");
+
+foreach ($methods as $method) {
+ var_dump($rc->$method());
+ var_dump($rc->$method(null));
+ var_dump($rc->$method('X', 0));
+}
+?>
+--EXPECTF--
+string(%d) "%s"
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 10
+NULL
+--UEXPECTF--
+unicode(%d) "%s"
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 10
+NULL
--- /dev/null
+--TEST--
+ReflectionObject::__construct - basic function test
+--FILE--
+<?php
+$r1 = new ReflectionObject(new stdClass);
+var_dump($r1);
+
+class C { }
+$myInstance = new C;
+$r2 = new ReflectionObject($myInstance);
+var_dump($r2);
+
+$r3 = new ReflectionObject($r2);
+var_dump($r3);
+?>
+--EXPECTF--
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(8) "stdClass"
+}
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(1) "C"
+}
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(16) "ReflectionObject"
+}
+--UEXPECTF--
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(8) "stdClass"
+}
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(1) "C"
+}
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(16) "ReflectionObject"
+}
--- /dev/null
+--TEST--
+ReflectionObject::__construct - invalid arguments
+--FILE--
+<?php
+
+var_dump(new ReflectionObject());
+var_dump(new ReflectionObject('stdClass'));
+$myInstance = new stdClass;
+var_dump(new ReflectionObject($myInstance, $myInstance));
+var_dump(new ReflectionObject(0));
+var_dump(new ReflectionObject(null));
+var_dump(new ReflectionObject(array(1,2)));
+?>
+--EXPECTF--
+Warning: ReflectionObject::__construct() expects exactly 1 parameter, 0 given in %s on line 3
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, string given in %s on line 4
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects exactly 1 parameter, 2 given in %s on line 6
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, integer given in %s on line 7
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, null given in %s on line 8
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, array given in %s on line 9
+object(ReflectionObject)#%d (1) {
+ ["name"]=>
+ string(0) ""
+}
+--UEXPECTF--
+Warning: ReflectionObject::__construct() expects exactly 1 parameter, 0 given in %s on line 3
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, Unicode string given in %s on line 4
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects exactly 1 parameter, 2 given in %s on line 6
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, integer given in %s on line 7
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, null given in %s on line 8
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(0) ""
+}
+
+Warning: ReflectionObject::__construct() expects parameter 1 to be object, array given in %s on line 9
+object(ReflectionObject)#%d (1) {
+ [u"name"]=>
+ unicode(0) ""
+}
--- /dev/null
+--TEST--
+ReflectionObject::getConstant() basic function test
+--FILE--
+<?php
+class C {
+ const a = 'hello from C';
+}
+class D extends C {
+}
+class E extends D {
+}
+class F extends E {
+ const a = 'hello from F';
+}
+class X {
+}
+
+$classes = array("C", "D", "E", "F", "X");
+foreach($classes as $class) {
+ echo "Reflecting on instance of class $class: \n";
+ $rc = new ReflectionObject(new $class);
+ var_dump($rc->getConstant('a'));
+ var_dump($rc->getConstant('doesntexist'));
+}
+?>
+--EXPECTF--
+Reflecting on instance of class C:
+string(12) "hello from C"
+bool(false)
+Reflecting on instance of class D:
+string(12) "hello from C"
+bool(false)
+Reflecting on instance of class E:
+string(12) "hello from C"
+bool(false)
+Reflecting on instance of class F:
+string(12) "hello from F"
+bool(false)
+Reflecting on instance of class X:
+bool(false)
+bool(false)
+--UEXPECTF--
+Reflecting on instance of class C:
+unicode(12) "hello from C"
+bool(false)
+Reflecting on instance of class D:
+unicode(12) "hello from C"
+bool(false)
+Reflecting on instance of class E:
+unicode(12) "hello from C"
+bool(false)
+Reflecting on instance of class F:
+unicode(12) "hello from F"
+bool(false)
+Reflecting on instance of class X:
+bool(false)
+bool(false)
--- /dev/null
+--TEST--
+ReflectionObject::getConstant() - invalid params
+--FILE--
+<?php
+class C {
+ const myConst = 1;
+}
+
+$rc = new ReflectionObject(new C);
+var_dump($rc->getConstant());
+var_dump($rc->getConstant("myConst", "myConst"));
+var_dump($rc->getConstant(null));
+var_dump($rc->getConstant(1));
+var_dump($rc->getConstant(1.5));
+var_dump($rc->getConstant(true));
+var_dump($rc->getConstant(array(1,2,3)));
+var_dump($rc->getConstant(new C));
+?>
+--EXPECTF--
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 0 given in %s on line 7
+NULL
+
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 2 given in %s on line 8
+NULL
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string (Unicode or binary), array given in %s on line 13
+NULL
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string (Unicode or binary), object given in %s on line 14
+NULL
+--UEXPECTF--
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 0 given in %s on line 7
+NULL
+
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 2 given in %s on line 8
+NULL
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string (Unicode or binary), array given in %s on line 13
+NULL
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string (Unicode or binary), object given in %s on line 14
+NULL
--- /dev/null
+--TEST--
+ReflectionObject::getConstants() - basic function test
+--FILE--
+<?php
+class C {
+ const a = 'hello from C';
+}
+class D extends C {
+}
+class E extends D {
+}
+class F extends E {
+ const a = 'hello from F';
+}
+class X {
+}
+
+$classes = array("C", "D", "E", "F", "X");
+foreach($classes as $class) {
+ echo "Reflecting on instance of class $class: \n";
+ $rc = new ReflectionObject(new $class);
+ var_dump($rc->getConstants());
+}
+
+?>
+--EXPECTF--
+Reflecting on instance of class C:
+array(1) {
+ ["a"]=>
+ string(12) "hello from C"
+}
+Reflecting on instance of class D:
+array(1) {
+ ["a"]=>
+ string(12) "hello from C"
+}
+Reflecting on instance of class E:
+array(1) {
+ ["a"]=>
+ string(12) "hello from C"
+}
+Reflecting on instance of class F:
+array(1) {
+ ["a"]=>
+ string(12) "hello from F"
+}
+Reflecting on instance of class X:
+array(0) {
+}
+--UEXPECTF--
+Reflecting on instance of class C:
+array(1) {
+ [u"a"]=>
+ unicode(12) "hello from C"
+}
+Reflecting on instance of class D:
+array(1) {
+ [u"a"]=>
+ unicode(12) "hello from C"
+}
+Reflecting on instance of class E:
+array(1) {
+ [u"a"]=>
+ unicode(12) "hello from C"
+}
+Reflecting on instance of class F:
+array(1) {
+ [u"a"]=>
+ unicode(12) "hello from F"
+}
+Reflecting on instance of class X:
+array(0) {
+}
--- /dev/null
+--TEST--
+ReflectionObject::getConstants() - invalid params
+--FILE--
+<?php
+class X {
+}
+
+$rc = new ReflectionObject(new X);
+
+$rc->getConstants('X');
+$rc->getConstants(true);
+
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 7
+
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 8
+--UEXPECTF--
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 7
+
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 8
+
--- /dev/null
+--TEST--
+ReflectionObject::getConstructor() - basic function test
+--FILE--
+<?php
+class NewCtor {
+ function __construct() {}
+}
+
+class ExtendsNewCtor extends NewCtor {
+}
+
+class OldCtor {
+ function OldCtor() {}
+}
+
+class ExtendsOldCtor extends OldCtor {
+}
+
+
+class X {
+ function Y() {}
+}
+
+class Y extends X {
+}
+
+class OldAndNewCtor {
+ function OldAndNewCtor() {}
+ function __construct() {}
+}
+
+class NewAndOldCtor {
+ function __construct() {}
+ function NewAndOldCtor() {}
+}
+class B {
+ function B() {}
+}
+
+class C extends B {
+ function C() {}
+}
+
+class D1 extends C {
+ function __construct() {}
+}
+
+class D2 extends C {
+}
+
+$classes = array('NewCtor', 'ExtendsNewCtor', 'OldCtor', 'ExtendsOldCtor',
+ 'OldAndNewCtor', 'NewAndOldCtor', 'B', 'C', 'D1', 'D2', 'X', 'Y');
+
+foreach ($classes as $class) {
+ $rc = new ReflectionObject(new $class);
+ $rm = $rc->getConstructor();
+ if ($rm != null) {
+ echo "Constructor of $class: " . $rm->getName() . "\n";
+ } else {
+ echo "No constructor for $class\n";
+ }
+
+}
+
+?>
+--EXPECTF--
+
+Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26
+
+Strict Standards: %s for class NewAndOldCtor in %s on line 31
+Constructor of NewCtor: __construct
+Constructor of ExtendsNewCtor: __construct
+Constructor of OldCtor: OldCtor
+Constructor of ExtendsOldCtor: OldCtor
+Constructor of OldAndNewCtor: __construct
+Constructor of NewAndOldCtor: __construct
+Constructor of B: B
+Constructor of C: C
+Constructor of D1: __construct
+Constructor of D2: C
+No constructor for X
+No constructor for Y
+--UEXPECTF--
+
+Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26
+
+Strict Standards: %s for class NewAndOldCtor in %s on line 31
+Constructor of NewCtor: __construct
+Constructor of ExtendsNewCtor: __construct
+Constructor of OldCtor: OldCtor
+Constructor of ExtendsOldCtor: OldCtor
+Constructor of OldAndNewCtor: __construct
+Constructor of NewAndOldCtor: __construct
+Constructor of B: B
+Constructor of C: C
+Constructor of D1: __construct
+Constructor of D2: C
+No constructor for X
+No constructor for Y
--- /dev/null
+--TEST--
+ReflectionObject::getConstructor() - invalid params
+--FILE--
+<?php
+class C {}
+$rc = new ReflectionObject(new C);
+var_dump($rc->getConstructor(null));
+var_dump($rc->getConstructor('X'));
+var_dump($rc->getConstructor(true));
+var_dump($rc->getConstructor(array(1,2,3)));
+?>
+--EXPECTF--
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 5
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 6
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 7
+NULL
+--UEXPECTF--
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 5
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 6
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 7
+NULL
--- /dev/null
+--TEST--
+ReflectionObject::getName() - basic function test
+--FILE--
+<?php
+$r0 = new ReflectionObject();
+var_dump($r0->getName());
+
+$r1 = new ReflectionObject(new stdClass);
+var_dump($r1->getName());
+
+class C { }
+$myInstance = new C;
+$r2 = new ReflectionObject($myInstance);
+var_dump($r2->getName());
+
+$r3 = new ReflectionObject($r2);
+var_dump($r3->getName());
+
+?>
+--EXPECTF--
+
+Warning: ReflectionObject::__construct() expects exactly 1 parameter, 0 given in %s on line 2
+string(0) ""
+string(8) "stdClass"
+string(1) "C"
+string(16) "ReflectionObject"
+--UEXPECTF--
+
+Warning: ReflectionObject::__construct() expects exactly 1 parameter, 0 given in %s on line 2
+unicode(0) ""
+unicode(8) "stdClass"
+unicode(1) "C"
+unicode(16) "ReflectionObject"
+
--- /dev/null
+--TEST--
+ReflectionObject::getname() - invalid params
+--FILE--
+<?php
+class C { }
+$myInstance = new C;
+$r2 = new ReflectionObject($myInstance);
+
+$r3 = new ReflectionObject($r2);
+
+var_dump($r3->getName(null));
+var_dump($r3->getName('x','y'));
+var_dump($r3->getName(0));
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 8
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 10
+NULL
+--UEXPECTF--
+Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 8
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 10
+NULL
--- /dev/null
+--TEST--
+ReflectionObject::getName - forbid static invocation
+--FILE--
+<?php
+ReflectionObject::getName();
+?>
+--EXPECTF--
+Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2
+--UEXPECTF--
+Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2
--- /dev/null
+--TEST--
+ReflectionObject::isInstance() - basic function test
+--FILE--
+<?php
+class A {}
+class B extends A {}
+class X {}
+
+$classes = array("A", "B", "X");
+
+$instances = array( "myA" => new A,
+ "myB" => new B,
+ "myX" => new X );
+
+foreach ($classes as $class) {
+ $ro = new ReflectionObject(new $class);
+ foreach ($instances as $name => $instance) {
+ echo "is $name a $class? ";
+ var_dump($ro->isInstance($instance));
+ }
+}
+
+?>
+--EXPECTF--
+is myA a A? bool(true)
+is myB a A? bool(false)
+is myX a A? bool(false)
+is myA a B? bool(false)
+is myB a B? bool(true)
+is myX a B? bool(false)
+is myA a X? bool(false)
+is myB a X? bool(false)
+is myX a X? bool(true)
+--UEXPECTF--
+is myA a A? bool(true)
+is myB a A? bool(false)
+is myX a A? bool(false)
+is myA a B? bool(false)
+is myB a B? bool(true)
+is myX a B? bool(false)
+is myA a X? bool(false)
+is myB a X? bool(false)
+is myX a X? bool(true)
--- /dev/null
+--TEST--
+ReflectionObject::isInstance() - invalid params
+--FILE--
+<?php
+class X {}
+$instance = new X;
+$ro = new ReflectionObject(new X);
+
+var_dump($ro->isInstance());
+var_dump($ro->isInstance($instance, $instance));
+var_dump($ro->isInstance(1));
+var_dump($ro->isInstance(1.5));
+var_dump($ro->isInstance(true));
+var_dump($ro->isInstance('X'));
+var_dump($ro->isInstance(null));
+
+?>
+--EXPECTF--
+Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 0 given in %s on line 6
+NULL
+
+Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 2 given in %s on line 7
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, integer given in %s on line 8
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, double given in %s on line 9
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, boolean given in %s on line 10
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, string given in %s on line 11
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, null given in %s on line 12
+NULL
+--UEXPECTF--
+Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 0 given in %s on line 6
+NULL
+
+Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 2 given in %s on line 7
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, integer given in %s on line 8
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, double given in %s on line 9
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, boolean given in %s on line 10
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, Unicode string given in %s on line 11
+NULL
+
+Warning: ReflectionClass::isInstance() expects parameter 1 to be object, null given in %s on line 12
+NULL
--- /dev/null
+--TEST--
+ReflectionObject::IsInstantiable() - basic function test
+--FILE--
+<?php
+class C {
+}
+
+interface iface {
+ function f1();
+}
+
+class ifaceImpl implements iface {
+ function f1() {}
+}
+
+abstract class abstractClass {
+ function f1() {}
+ abstract function f2();
+}
+
+class D extends abstractClass {
+ function f2() {}
+}
+
+$classes = array("C", "ifaceImpl", "D");
+
+foreach($classes as $class ) {
+ $ro = new ReflectionObject(new $class);
+ echo "Is $class instantiable? ";
+ var_dump($ro->IsInstantiable());
+}
+?>
+--EXPECTF--
+Is C instantiable? bool(true)
+Is ifaceImpl instantiable? bool(true)
+Is D instantiable? bool(true)
+--UEXPECTF--
+Is C instantiable? bool(true)
+Is ifaceImpl instantiable? bool(true)
+Is D instantiable? bool(true)
--- /dev/null
+--TEST--
+ReflectionObject::IsInstantiable() - invalid params
+--FILE--
+<?php
+class privateCtorOld {
+ private function privateCtorOld() {}
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+$reflectionObject = privateCtorOld::reflectionObjectFactory();
+
+var_dump($reflectionObject->IsInstantiable('X'));
+var_dump($reflectionObject->IsInstantiable(0, null));
+
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 10
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 11
+NULL
+--UEXPECTF--
+Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 10
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 11
+NULL
--- /dev/null
+--TEST--
+ReflectionObject::IsInstantiable() - variation - constructors
+--FILE--
+<?php
+
+class noCtor {
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+
+class publicCtorNew {
+ public function __construct() {}
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+
+class protectedCtorNew {
+ protected function __construct() {}
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+
+class privateCtorNew {
+ private function __construct() {}
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+
+class publicCtorOld {
+ public function publicCtorOld() {}
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+
+class protectedCtorOld {
+ protected function protectedCtorOld() {}
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+
+class privateCtorOld {
+ private function privateCtorOld() {}
+ public static function reflectionObjectFactory() {
+ return new ReflectionObject(new self);
+ }
+}
+
+
+$reflectionObjects = array(
+ noCtor::reflectionObjectFactory(),
+ publicCtorNew::reflectionObjectFactory(),
+ protectedCtorNew::reflectionObjectFactory(),
+ privateCtorNew::reflectionObjectFactory(),
+ publicCtorOld::reflectionObjectFactory(),
+ protectedCtorOld::reflectionObjectFactory(),
+ privateCtorOld::reflectionObjectFactory()
+ );
+
+foreach($reflectionObjects as $reflectionObject ) {
+ $name = $reflectionObject->getName();
+ echo "Is $name instantiable? ";
+ var_dump($reflectionObject->IsInstantiable());
+}
+?>
+--EXPECTF--
+Is noCtor instantiable? bool(true)
+Is publicCtorNew instantiable? bool(true)
+Is protectedCtorNew instantiable? bool(false)
+Is privateCtorNew instantiable? bool(false)
+Is publicCtorOld instantiable? bool(true)
+Is protectedCtorOld instantiable? bool(false)
+Is privateCtorOld instantiable? bool(false)
+--UEXPECTF--
+Is noCtor instantiable? bool(true)
+Is publicCtorNew instantiable? bool(true)
+Is protectedCtorNew instantiable? bool(false)
+Is privateCtorNew instantiable? bool(false)
+Is publicCtorOld instantiable? bool(true)
+Is protectedCtorOld instantiable? bool(false)
+Is privateCtorOld instantiable? bool(false)
--- /dev/null
+--TEST--
+ReflectionObject::isInternal() - basic function test
+--FILE--
+<?php
+class C {
+}
+
+$r1 = new ReflectionObject(new stdClass);
+$r2 = new ReflectionObject(new ReflectionClass('C'));
+$r3 = new ReflectionObject(new ReflectionProperty('Exception', 'message'));
+$r4 = new ReflectionObject(new Exception);
+$r5 = new ReflectionObject(new C);
+
+var_dump($r1->isInternal(), $r2->isInternal(), $r3->isInternal(),
+ $r4->isInternal(), $r5->isInternal());
+
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+--UEXPECTF--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
--- /dev/null
+--TEST--
+ReflectionObject::isInternal() - invalid params
+--FILE--
+<?php
+
+$r1 = new ReflectionObject(new stdClass);
+var_dump($r1->isInternal('X'));
+var_dump($r1->isInternal('X', true));
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 5
+NULL
+--UEXPECTF--
+Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 5
+NULL
--- /dev/null
+--TEST--
+ReflectionObject::isSubclassOf() - basic function test
+--FILE--
+<?php
+class A {}
+class B extends A {}
+class C extends B {}
+
+interface I {}
+class X implements I {}
+
+$classNames = array('A', 'B', 'C', 'I', 'X');
+
+//Create ReflectionClasses
+foreach ($classNames as $className) {
+ $rcs[$className] = new ReflectionClass($className);
+}
+
+//Create ReflectionObjects
+foreach ($classNames as $className) {
+ if ($rcs[$className]->isInstantiable()) {
+ $ros[$className] = new ReflectionObject(new $className);
+ }
+}
+
+foreach ($ros as $childName => $child) {
+ foreach ($rcs as $parentName => $parent) {
+ echo "Is " . $childName . " a subclass of " . $parentName . "? \n";
+ echo " - Using ReflectionClass object argument: ";
+ var_dump($child->isSubclassOf($parent));
+ if ($parent->isInstantiable()) {
+ echo " - Using ReflectionObject object argument: ";
+ var_dump($child->isSubclassOf($ros[$parentName]));
+ }
+ echo " - Using string argument: ";
+ var_dump($child->isSubclassOf($parentName));
+ }
+}
+?>
+--EXPECTF--
+Is A a subclass of A?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of B?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of I?
+ - Using ReflectionClass object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of A?
+ - Using ReflectionClass object argument: bool(true)
+ - Using ReflectionObject object argument: bool(true)
+ - Using string argument: bool(true)
+Is B a subclass of B?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of I?
+ - Using ReflectionClass object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is C a subclass of A?
+ - Using ReflectionClass object argument: bool(true)
+ - Using ReflectionObject object argument: bool(true)
+ - Using string argument: bool(true)
+Is C a subclass of B?
+ - Using ReflectionClass object argument: bool(true)
+ - Using ReflectionObject object argument: bool(true)
+ - Using string argument: bool(true)
+Is C a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is C a subclass of I?
+ - Using ReflectionClass object argument: bool(false)
+ - Using string argument: bool(false)
+Is C a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of A?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of B?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of I?
+ - Using ReflectionClass object argument: bool(true)
+ - Using string argument: bool(true)
+Is X a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+--UEXPECTF--
+Is A a subclass of A?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of B?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of I?
+ - Using ReflectionClass object argument: bool(false)
+ - Using string argument: bool(false)
+Is A a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of A?
+ - Using ReflectionClass object argument: bool(true)
+ - Using ReflectionObject object argument: bool(true)
+ - Using string argument: bool(true)
+Is B a subclass of B?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of I?
+ - Using ReflectionClass object argument: bool(false)
+ - Using string argument: bool(false)
+Is B a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is C a subclass of A?
+ - Using ReflectionClass object argument: bool(true)
+ - Using ReflectionObject object argument: bool(true)
+ - Using string argument: bool(true)
+Is C a subclass of B?
+ - Using ReflectionClass object argument: bool(true)
+ - Using ReflectionObject object argument: bool(true)
+ - Using string argument: bool(true)
+Is C a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is C a subclass of I?
+ - Using ReflectionClass object argument: bool(false)
+ - Using string argument: bool(false)
+Is C a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of A?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of B?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of C?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
+Is X a subclass of I?
+ - Using ReflectionClass object argument: bool(true)
+ - Using string argument: bool(true)
+Is X a subclass of X?
+ - Using ReflectionClass object argument: bool(false)
+ - Using ReflectionObject object argument: bool(false)
+ - Using string argument: bool(false)
--- /dev/null
+--TEST--
+ReflectionObject::isSubclassOf() - invalid params
+--FILE--
+<?php
+class A {}
+$ro = new ReflectionObject(new A);
+
+var_dump($ro->isSubclassOf());
+var_dump($ro->isSubclassOf('A',5));
+var_dump($ro->isSubclassOf('X'));
+
+?>
+--EXPECTF--
+Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 5
+NULL
+
+Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 6
+NULL
+
+Fatal error: Uncaught exception 'ReflectionException' with message 'Class X does not exist' in %s:7
+Stack trace:
+#0 %s(7): ReflectionClass->isSubclassOf('X')
+#1 {main}
+ thrown in %s on line 7
+--UEXPECTF--
+Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 5
+NULL
+
+Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 6
+NULL
+
+Fatal error: Uncaught exception 'ReflectionException' with message 'Class X does not exist' in %s:7
+Stack trace:
+#0 %s(7): ReflectionClass->isSubclassOf('X')
+#1 {main}
+ thrown in %s on line 7
--- /dev/null
+--TEST--
+ReflectionObject::isUserDefined() - basic function test
+--FILE--
+<?php
+class C {
+}
+
+$r1 = new ReflectionObject(new stdClass);
+$r2 = new ReflectionObject(new ReflectionClass('C'));
+$r3 = new ReflectionObject(new ReflectionProperty('Exception', 'message'));
+$r4 = new ReflectionObject(new Exception);
+$r5 = new ReflectionObject(new C);
+
+var_dump($r1->isUserDefined(), $r2->isUserDefined(), $r3->isUserDefined(),
+ $r4->isUserDefined(), $r5->isUserDefined());
+
+?>
+--EXPECTF--
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(true)
+--UEXPECTF--
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(true)
--- /dev/null
+--TEST--
+ReflectionObject::isUserDefined() - invalid params
+--FILE--
+<?php
+$r1 = new ReflectionObject(new stdClass);
+
+var_dump($r1->isUserDefined('X'));
+var_dump($r1->isUserDefined('X', true));
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 5
+NULL
+--UEXPECTF--
+Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 5
+NULL