mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Adding PHPT tests for the ReflectionMethod class.
This commit is contained in:
300
ext/reflection/tests/ReflectionMethod_basic1.phpt
Normal file
300
ext/reflection/tests/ReflectionMethod_basic1.phpt
Normal file
@@ -0,0 +1,300 @@
|
||||
--TEST--
|
||||
ReflectionMethod class - various methods
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function reflectMethod($class, $method) {
|
||||
$methodInfo = new ReflectionMethod($class, $method);
|
||||
echo "**********************************\n";
|
||||
echo "Reflecting on method $class::$method()\n\n";
|
||||
echo "\nisFinal():\n";
|
||||
var_dump($methodInfo->isFinal());
|
||||
echo "\nisAbstract():\n";
|
||||
var_dump($methodInfo->isAbstract());
|
||||
echo "\nisPublic():\n";
|
||||
var_dump($methodInfo->isPublic());
|
||||
echo "\nisPrivate():\n";
|
||||
var_dump($methodInfo->isPrivate());
|
||||
echo "\nisProtected():\n";
|
||||
var_dump($methodInfo->isProtected());
|
||||
echo "\nisStatic():\n";
|
||||
var_dump($methodInfo->isStatic());
|
||||
echo "\nisConstructor():\n";
|
||||
var_dump($methodInfo->isConstructor());
|
||||
echo "\nisDestructor():\n";
|
||||
var_dump($methodInfo->isDestructor());
|
||||
echo "\n**********************************\n";
|
||||
}
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public function foo() {
|
||||
echo "Called foo()\n";
|
||||
}
|
||||
|
||||
static function stat() {
|
||||
echo "Called stat()\n";
|
||||
}
|
||||
|
||||
private function priv() {
|
||||
echo "Called priv()\n";
|
||||
}
|
||||
|
||||
protected function prot() {}
|
||||
|
||||
public function __destruct() {}
|
||||
}
|
||||
|
||||
class DerivedClass extends TestClass {}
|
||||
|
||||
interface TestInterface {
|
||||
public function int();
|
||||
}
|
||||
|
||||
reflectMethod("DerivedClass", "foo");
|
||||
reflectMethod("TestClass", "stat");
|
||||
reflectMethod("TestClass", "priv");
|
||||
reflectMethod("TestClass", "prot");
|
||||
reflectMethod("DerivedClass", "prot");
|
||||
reflectMethod("TestInterface", "int");
|
||||
reflectMethod("ReflectionProperty", "__construct");
|
||||
reflectMethod("TestClass", "__destruct");
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::foo()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(false)
|
||||
|
||||
isPublic():
|
||||
bool(true)
|
||||
|
||||
isPrivate():
|
||||
bool(false)
|
||||
|
||||
isProtected():
|
||||
bool(false)
|
||||
|
||||
isStatic():
|
||||
bool(false)
|
||||
|
||||
isConstructor():
|
||||
bool(false)
|
||||
|
||||
isDestructor():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::stat()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(false)
|
||||
|
||||
isPublic():
|
||||
bool(true)
|
||||
|
||||
isPrivate():
|
||||
bool(false)
|
||||
|
||||
isProtected():
|
||||
bool(false)
|
||||
|
||||
isStatic():
|
||||
bool(true)
|
||||
|
||||
isConstructor():
|
||||
bool(false)
|
||||
|
||||
isDestructor():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::priv()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(false)
|
||||
|
||||
isPublic():
|
||||
bool(false)
|
||||
|
||||
isPrivate():
|
||||
bool(true)
|
||||
|
||||
isProtected():
|
||||
bool(false)
|
||||
|
||||
isStatic():
|
||||
bool(false)
|
||||
|
||||
isConstructor():
|
||||
bool(false)
|
||||
|
||||
isDestructor():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::prot()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(false)
|
||||
|
||||
isPublic():
|
||||
bool(false)
|
||||
|
||||
isPrivate():
|
||||
bool(false)
|
||||
|
||||
isProtected():
|
||||
bool(true)
|
||||
|
||||
isStatic():
|
||||
bool(false)
|
||||
|
||||
isConstructor():
|
||||
bool(false)
|
||||
|
||||
isDestructor():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::prot()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(false)
|
||||
|
||||
isPublic():
|
||||
bool(false)
|
||||
|
||||
isPrivate():
|
||||
bool(false)
|
||||
|
||||
isProtected():
|
||||
bool(true)
|
||||
|
||||
isStatic():
|
||||
bool(false)
|
||||
|
||||
isConstructor():
|
||||
bool(false)
|
||||
|
||||
isDestructor():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestInterface::int()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(true)
|
||||
|
||||
isPublic():
|
||||
bool(true)
|
||||
|
||||
isPrivate():
|
||||
bool(false)
|
||||
|
||||
isProtected():
|
||||
bool(false)
|
||||
|
||||
isStatic():
|
||||
bool(false)
|
||||
|
||||
isConstructor():
|
||||
bool(false)
|
||||
|
||||
isDestructor():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method ReflectionProperty::__construct()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(false)
|
||||
|
||||
isPublic():
|
||||
bool(true)
|
||||
|
||||
isPrivate():
|
||||
bool(false)
|
||||
|
||||
isProtected():
|
||||
bool(false)
|
||||
|
||||
isStatic():
|
||||
bool(false)
|
||||
|
||||
isConstructor():
|
||||
bool(true)
|
||||
|
||||
isDestructor():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::__destruct()
|
||||
|
||||
|
||||
isFinal():
|
||||
bool(false)
|
||||
|
||||
isAbstract():
|
||||
bool(false)
|
||||
|
||||
isPublic():
|
||||
bool(true)
|
||||
|
||||
isPrivate():
|
||||
bool(false)
|
||||
|
||||
isProtected():
|
||||
bool(false)
|
||||
|
||||
isStatic():
|
||||
bool(false)
|
||||
|
||||
isConstructor():
|
||||
bool(false)
|
||||
|
||||
isDestructor():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
|
||||
|
||||
323
ext/reflection/tests/ReflectionMethod_basic2.phpt
Normal file
323
ext/reflection/tests/ReflectionMethod_basic2.phpt
Normal file
@@ -0,0 +1,323 @@
|
||||
--TEST--
|
||||
ReflectionMethod class __toString() and export() methods
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function reflectMethod($class, $method) {
|
||||
$methodInfo = new ReflectionMethod($class, $method);
|
||||
echo "**********************************\n";
|
||||
echo "Reflecting on method $class::$method()\n\n";
|
||||
echo "__toString():\n";
|
||||
var_dump($methodInfo->__toString());
|
||||
echo "\nexport():\n";
|
||||
var_dump(ReflectionMethod::export($class, $method, true));
|
||||
echo "\n**********************************\n";
|
||||
}
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public function foo() {
|
||||
echo "Called foo()\n";
|
||||
}
|
||||
|
||||
static function stat() {
|
||||
echo "Called stat()\n";
|
||||
}
|
||||
|
||||
private function priv() {
|
||||
echo "Called priv()\n";
|
||||
}
|
||||
|
||||
protected function prot() {}
|
||||
|
||||
public function __destruct() {}
|
||||
}
|
||||
|
||||
class DerivedClass extends TestClass {}
|
||||
|
||||
interface TestInterface {
|
||||
public function int();
|
||||
}
|
||||
|
||||
reflectMethod("DerivedClass", "foo");
|
||||
reflectMethod("TestClass", "stat");
|
||||
reflectMethod("TestClass", "priv");
|
||||
reflectMethod("TestClass", "prot");
|
||||
reflectMethod("DerivedClass", "prot");
|
||||
reflectMethod("TestInterface", "int");
|
||||
reflectMethod("ReflectionProperty", "__construct");
|
||||
reflectMethod("TestClass", "__destruct");
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::foo()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <user, inherits TestClass> public method foo ] {
|
||||
@@ %s 16 - 18
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <user, inherits TestClass> public method foo ] {
|
||||
@@ %s 16 - 18
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::stat()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <user> static public method stat ] {
|
||||
@@ %s 20 - 22
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <user> static public method stat ] {
|
||||
@@ %s 20 - 22
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::priv()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <user> private method priv ] {
|
||||
@@ %s 24 - 26
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <user> private method priv ] {
|
||||
@@ %s 24 - 26
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::prot()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <user> protected method prot ] {
|
||||
@@ %s 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <user> protected method prot ] {
|
||||
@@ %s 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::prot()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <user, inherits TestClass> protected method prot ] {
|
||||
@@ %s 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <user, inherits TestClass> protected method prot ] {
|
||||
@@ %s 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestInterface::int()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <user> abstract public method int ] {
|
||||
@@ %s 36 - 36
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <user> abstract public method int ] {
|
||||
@@ %s 36 - 36
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method ReflectionProperty::__construct()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <internal:Reflection, ctor> public method __construct ] {
|
||||
|
||||
- Parameters [1] {
|
||||
Parameter #0 [ <required> $argument ]
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <internal:Reflection, ctor> public method __construct ] {
|
||||
|
||||
- Parameters [1] {
|
||||
Parameter #0 [ <required> $argument ]
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::__destruct()
|
||||
|
||||
__toString():
|
||||
string(%d) "Method [ <user, dtor> public method __destruct ] {
|
||||
@@ %s 30 - 30
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
string(%d) "Method [ <user, dtor> public method __destruct ] {
|
||||
@@ %s 30 - 30
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
--UEXPECTF--
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::foo()
|
||||
|
||||
__toString():
|
||||
unicode(%d) "Method [ <user, inherits TestClass> public method foo ] {
|
||||
@@ %sReflectionMethod_basic2.php 16 - 18
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(%d) "Method [ <user, inherits TestClass> public method foo ] {
|
||||
@@ %sReflectionMethod_basic2.php 16 - 18
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::stat()
|
||||
|
||||
__toString():
|
||||
unicode(%d) "Method [ <user> static public method stat ] {
|
||||
@@ %sReflectionMethod_basic2.php 20 - 22
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(%d) "Method [ <user> static public method stat ] {
|
||||
@@ %sReflectionMethod_basic2.php 20 - 22
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::priv()
|
||||
|
||||
__toString():
|
||||
unicode(%d) "Method [ <user> private method priv ] {
|
||||
@@ %sReflectionMethod_basic2.php 24 - 26
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(%d) "Method [ <user> private method priv ] {
|
||||
@@ %sReflectionMethod_basic2.php 24 - 26
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::prot()
|
||||
|
||||
__toString():
|
||||
unicode(%d) "Method [ <user> protected method prot ] {
|
||||
@@ %sReflectionMethod_basic2.php 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(%d) "Method [ <user> protected method prot ] {
|
||||
@@ %sReflectionMethod_basic2.php 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::prot()
|
||||
|
||||
__toString():
|
||||
unicode(%d) "Method [ <user, inherits TestClass> protected method prot ] {
|
||||
@@ %sReflectionMethod_basic2.php 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(%d) "Method [ <user, inherits TestClass> protected method prot ] {
|
||||
@@ %sReflectionMethod_basic2.php 28 - 28
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestInterface::int()
|
||||
|
||||
__toString():
|
||||
unicode(%d) "Method [ <user> abstract public method int ] {
|
||||
@@ %sReflectionMethod_basic2.php 36 - 36
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(%d) "Method [ <user> abstract public method int ] {
|
||||
@@ %sReflectionMethod_basic2.php 36 - 36
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method ReflectionProperty::__construct()
|
||||
|
||||
__toString():
|
||||
unicode(137) "Method [ <internal:Reflection, ctor> public method __construct ] {
|
||||
|
||||
- Parameters [1] {
|
||||
Parameter #0 [ <required> $argument ]
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(137) "Method [ <internal:Reflection, ctor> public method __construct ] {
|
||||
|
||||
- Parameters [1] {
|
||||
Parameter #0 [ <required> $argument ]
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::__destruct()
|
||||
|
||||
__toString():
|
||||
unicode(%d) "Method [ <user, dtor> public method __destruct ] {
|
||||
@@ %sReflectionMethod_basic2.php 30 - 30
|
||||
}
|
||||
"
|
||||
|
||||
export():
|
||||
unicode(%d) "Method [ <user, dtor> public method __destruct ] {
|
||||
@@ %sReflectionMethod_basic2.php 30 - 30
|
||||
}
|
||||
"
|
||||
|
||||
**********************************
|
||||
282
ext/reflection/tests/ReflectionMethod_basic3.phpt
Normal file
282
ext/reflection/tests/ReflectionMethod_basic3.phpt
Normal file
@@ -0,0 +1,282 @@
|
||||
--TEST--
|
||||
ReflectionMethod class getName(), isInternal() and isUserDefined() methods
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function reflectMethod($class, $method) {
|
||||
$methodInfo = new ReflectionMethod($class, $method);
|
||||
echo "**********************************\n";
|
||||
echo "Reflecting on method $class::$method()\n\n";
|
||||
echo "\ngetName():\n";
|
||||
var_dump($methodInfo->getName());
|
||||
echo "\nisInternal():\n";
|
||||
var_dump($methodInfo->isInternal());
|
||||
echo "\nisUserDefined():\n";
|
||||
var_dump($methodInfo->isUserDefined());
|
||||
echo "\n**********************************\n";
|
||||
}
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public function foo() {
|
||||
echo "Called foo()\n";
|
||||
}
|
||||
|
||||
static function stat() {
|
||||
echo "Called stat()\n";
|
||||
}
|
||||
|
||||
private function priv() {
|
||||
echo "Called priv()\n";
|
||||
}
|
||||
|
||||
protected function prot() {}
|
||||
|
||||
public function __destruct() {}
|
||||
}
|
||||
|
||||
class DerivedClass extends TestClass {}
|
||||
|
||||
interface TestInterface {
|
||||
public function int();
|
||||
}
|
||||
|
||||
reflectMethod("DerivedClass", "foo");
|
||||
reflectMethod("TestClass", "stat");
|
||||
reflectMethod("TestClass", "priv");
|
||||
reflectMethod("TestClass", "prot");
|
||||
reflectMethod("DerivedClass", "prot");
|
||||
reflectMethod("TestInterface", "int");
|
||||
reflectMethod("ReflectionProperty", "__construct");
|
||||
reflectMethod("TestClass", "__destruct");
|
||||
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::foo()
|
||||
|
||||
|
||||
getName():
|
||||
string(3) "foo"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::stat()
|
||||
|
||||
|
||||
getName():
|
||||
string(4) "stat"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::priv()
|
||||
|
||||
|
||||
getName():
|
||||
string(4) "priv"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::prot()
|
||||
|
||||
|
||||
getName():
|
||||
string(4) "prot"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::prot()
|
||||
|
||||
|
||||
getName():
|
||||
string(4) "prot"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestInterface::int()
|
||||
|
||||
|
||||
getName():
|
||||
string(3) "int"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method ReflectionProperty::__construct()
|
||||
|
||||
|
||||
getName():
|
||||
string(11) "__construct"
|
||||
|
||||
isInternal():
|
||||
bool(true)
|
||||
|
||||
isUserDefined():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::__destruct()
|
||||
|
||||
|
||||
getName():
|
||||
string(10) "__destruct"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
--UEXPECT--
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::foo()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(3) "foo"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::stat()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(4) "stat"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::priv()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(4) "priv"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::prot()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(4) "prot"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::prot()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(4) "prot"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestInterface::int()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(3) "int"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method ReflectionProperty::__construct()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(11) "__construct"
|
||||
|
||||
isInternal():
|
||||
bool(true)
|
||||
|
||||
isUserDefined():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::__destruct()
|
||||
|
||||
|
||||
getName():
|
||||
unicode(10) "__destruct"
|
||||
|
||||
isInternal():
|
||||
bool(false)
|
||||
|
||||
isUserDefined():
|
||||
bool(true)
|
||||
|
||||
**********************************
|
||||
285
ext/reflection/tests/ReflectionMethod_basic4.phpt
Normal file
285
ext/reflection/tests/ReflectionMethod_basic4.phpt
Normal file
@@ -0,0 +1,285 @@
|
||||
--TEST--
|
||||
ReflectionMethod class getFileName(), getStartLine() and getEndLine() methods
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function reflectMethod($class, $method) {
|
||||
$methodInfo = new ReflectionMethod($class, $method);
|
||||
echo "**********************************\n";
|
||||
echo "Reflecting on method $class::$method()\n\n";
|
||||
echo "\ngetFileName():\n";
|
||||
var_dump($methodInfo->getFileName());
|
||||
echo "\ngetStartLine():\n";
|
||||
var_dump($methodInfo->getStartLine());
|
||||
echo "\ngetEndLine():\n";
|
||||
var_dump($methodInfo->getEndLine());
|
||||
echo "\n**********************************\n";
|
||||
}
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public function foo() {
|
||||
|
||||
|
||||
echo "Called foo()\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
static function stat() {
|
||||
echo "Called stat()\n";
|
||||
}
|
||||
|
||||
private function priv() {
|
||||
echo "Called priv()\n";
|
||||
}
|
||||
|
||||
protected function prot() {}
|
||||
|
||||
public function __destruct() {}
|
||||
}
|
||||
|
||||
class DerivedClass extends TestClass {}
|
||||
|
||||
interface TestInterface {
|
||||
public function int();
|
||||
}
|
||||
|
||||
reflectMethod("DerivedClass", "foo");
|
||||
reflectMethod("TestClass", "stat");
|
||||
reflectMethod("TestClass", "priv");
|
||||
reflectMethod("TestClass", "prot");
|
||||
reflectMethod("DerivedClass", "prot");
|
||||
reflectMethod("TestInterface", "int");
|
||||
reflectMethod("ReflectionProperty", "__construct");
|
||||
reflectMethod("TestClass", "__destruct");
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::foo()
|
||||
|
||||
|
||||
getFileName():
|
||||
string(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(18)
|
||||
|
||||
getEndLine():
|
||||
int(24)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::stat()
|
||||
|
||||
|
||||
getFileName():
|
||||
string(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(26)
|
||||
|
||||
getEndLine():
|
||||
int(28)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::priv()
|
||||
|
||||
|
||||
getFileName():
|
||||
string(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(30)
|
||||
|
||||
getEndLine():
|
||||
int(32)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::prot()
|
||||
|
||||
|
||||
getFileName():
|
||||
string(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(34)
|
||||
|
||||
getEndLine():
|
||||
int(34)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::prot()
|
||||
|
||||
|
||||
getFileName():
|
||||
string(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(34)
|
||||
|
||||
getEndLine():
|
||||
int(34)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestInterface::int()
|
||||
|
||||
|
||||
getFileName():
|
||||
string(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(42)
|
||||
|
||||
getEndLine():
|
||||
int(42)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method ReflectionProperty::__construct()
|
||||
|
||||
|
||||
getFileName():
|
||||
bool(false)
|
||||
|
||||
getStartLine():
|
||||
bool(false)
|
||||
|
||||
getEndLine():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::__destruct()
|
||||
|
||||
|
||||
getFileName():
|
||||
string(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(36)
|
||||
|
||||
getEndLine():
|
||||
int(36)
|
||||
|
||||
**********************************
|
||||
--UEXPECTF--
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::foo()
|
||||
|
||||
|
||||
getFileName():
|
||||
unicode(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(18)
|
||||
|
||||
getEndLine():
|
||||
int(24)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::stat()
|
||||
|
||||
|
||||
getFileName():
|
||||
unicode(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(26)
|
||||
|
||||
getEndLine():
|
||||
int(28)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::priv()
|
||||
|
||||
|
||||
getFileName():
|
||||
unicode(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(30)
|
||||
|
||||
getEndLine():
|
||||
int(32)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::prot()
|
||||
|
||||
|
||||
getFileName():
|
||||
unicode(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(34)
|
||||
|
||||
getEndLine():
|
||||
int(34)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method DerivedClass::prot()
|
||||
|
||||
|
||||
getFileName():
|
||||
unicode(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(34)
|
||||
|
||||
getEndLine():
|
||||
int(34)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestInterface::int()
|
||||
|
||||
|
||||
getFileName():
|
||||
unicode(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(42)
|
||||
|
||||
getEndLine():
|
||||
int(42)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method ReflectionProperty::__construct()
|
||||
|
||||
|
||||
getFileName():
|
||||
bool(false)
|
||||
|
||||
getStartLine():
|
||||
bool(false)
|
||||
|
||||
getEndLine():
|
||||
bool(false)
|
||||
|
||||
**********************************
|
||||
**********************************
|
||||
Reflecting on method TestClass::__destruct()
|
||||
|
||||
|
||||
getFileName():
|
||||
unicode(%d) "%sReflectionMethod_basic4.php"
|
||||
|
||||
getStartLine():
|
||||
int(36)
|
||||
|
||||
getEndLine():
|
||||
int(36)
|
||||
|
||||
**********************************
|
||||
121
ext/reflection/tests/ReflectionMethod_constructor_basic.phpt
Normal file
121
ext/reflection/tests/ReflectionMethod_constructor_basic.phpt
Normal file
@@ -0,0 +1,121 @@
|
||||
--TEST--
|
||||
ReflectionMethod::isConstructor()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class NewCtor {
|
||||
function __construct() {
|
||||
echo "In " . __METHOD__ . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
echo "New-style constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("NewCtor::__construct");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
class ExtendsNewCtor extends NewCtor {
|
||||
}
|
||||
echo "\nInherited new-style constructor\n";
|
||||
$methodInfo = new ReflectionMethod("ExtendsNewCtor::__construct");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
class OldCtor {
|
||||
function OldCtor() {
|
||||
echo "In " . __METHOD__ . "\n";
|
||||
}
|
||||
}
|
||||
echo "\nOld-style constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("OldCtor::OldCtor");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
class ExtendsOldCtor extends OldCtor {
|
||||
}
|
||||
echo "\nInherited old-style constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("ExtendsOldCtor::OldCtor");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
class X {
|
||||
function Y() {
|
||||
echo "In " . __METHOD__ . "\n";
|
||||
}
|
||||
}
|
||||
echo "\nNot a constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("X::Y");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
class Y extends X {
|
||||
}
|
||||
echo "\nInherited method of the same name as the class:\n";
|
||||
$methodInfo = new ReflectionMethod("Y::Y");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
class OldAndNewCtor {
|
||||
function OldAndNewCtor() {
|
||||
echo "In " . __METHOD__ . "\n";
|
||||
}
|
||||
|
||||
function __construct() {
|
||||
echo "In " . __METHOD__ . "\n";
|
||||
}
|
||||
}
|
||||
echo "\nOld-style constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("OldAndNewCtor::OldAndNewCtor");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
echo "\nRedefined constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("OldAndNewCtor::__construct");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
class NewAndOldCtor {
|
||||
function __construct() {
|
||||
echo "In " . __METHOD__ . "\n";
|
||||
}
|
||||
|
||||
function NewAndOldCtor() {
|
||||
echo "In " . __METHOD__ . "\n";
|
||||
}
|
||||
}
|
||||
echo "\nNew-style constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("NewAndOldCtor::__construct");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
echo "\nRedefined old-style constructor:\n";
|
||||
$methodInfo = new ReflectionMethod("NewAndOldCtor::NewAndOldCtor");
|
||||
var_dump($methodInfo->isConstructor());
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
|
||||
|
||||
Strict Standards: %s for class NewAndOldCtor in %s on line %d
|
||||
New-style constructor:
|
||||
bool(true)
|
||||
|
||||
Inherited new-style constructor
|
||||
bool(true)
|
||||
|
||||
Old-style constructor:
|
||||
bool(true)
|
||||
|
||||
Inherited old-style constructor:
|
||||
bool(true)
|
||||
|
||||
Not a constructor:
|
||||
bool(false)
|
||||
|
||||
Inherited method of the same name as the class:
|
||||
bool(false)
|
||||
|
||||
Old-style constructor:
|
||||
bool(false)
|
||||
|
||||
Redefined constructor:
|
||||
bool(true)
|
||||
|
||||
New-style constructor:
|
||||
bool(true)
|
||||
|
||||
Redefined old-style constructor:
|
||||
bool(false)
|
||||
@@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
ReflectionMethod::getDeclaringClass()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class A {
|
||||
function foo() {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
function bar() {}
|
||||
}
|
||||
|
||||
$methodInfo = new ReflectionMethod('B', 'foo');
|
||||
var_dump($methodInfo->getDeclaringClass());
|
||||
|
||||
$methodInfo = new ReflectionMethod('B', 'bar');
|
||||
var_dump($methodInfo->getDeclaringClass());
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
object(ReflectionClass)#%d (1) {
|
||||
["name"]=>
|
||||
string(1) "A"
|
||||
}
|
||||
object(ReflectionClass)#%d (1) {
|
||||
["name"]=>
|
||||
string(1) "B"
|
||||
}
|
||||
--UEXPECTF--
|
||||
object(ReflectionClass)#%d (1) {
|
||||
[u"name"]=>
|
||||
unicode(1) "A"
|
||||
}
|
||||
object(ReflectionClass)#%d (1) {
|
||||
[u"name"]=>
|
||||
unicode(1) "B"
|
||||
}
|
||||
163
ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt
Normal file
163
ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt
Normal file
@@ -0,0 +1,163 @@
|
||||
--TEST--
|
||||
ReflectionMethod::getDocComment()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/**
|
||||
* My Doc Comment for A
|
||||
*/
|
||||
class A {
|
||||
/**
|
||||
* My Doc Comment for A::f
|
||||
*/
|
||||
function f() {}
|
||||
|
||||
/**
|
||||
* My Doc Comment for A::privf
|
||||
*/
|
||||
private function privf() {}
|
||||
|
||||
/** My Doc Comment for A::protStatf */
|
||||
protected static function protStatf() {}
|
||||
|
||||
/**
|
||||
|
||||
* My Doc Comment for A::finalStatPubf
|
||||
*/
|
||||
final static public function finalStatPubf() {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class B extends A {
|
||||
/*** Not a doc comment */
|
||||
function f() {}
|
||||
|
||||
/** *
|
||||
* My Doc Comment for B::privf
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
private function privf() {}
|
||||
|
||||
|
||||
/** My Doc Comment for B::protStatf
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
protected static function protStatf() {}
|
||||
|
||||
}
|
||||
|
||||
foreach (array('A', 'B') as $class) {
|
||||
$rc = new ReflectionClass($class);
|
||||
$rms = $rc->getMethods();
|
||||
foreach ($rms as $rm) {
|
||||
echo "\n\n---> Doc comment for $class::" . $rm->getName() . "():\n";
|
||||
var_dump($rm->getDocComment());
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
|
||||
---> Doc comment for A::f():
|
||||
string(%d) "/**
|
||||
* My Doc Comment for A::f
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for A::privf():
|
||||
string(%d) "/**
|
||||
* My Doc Comment for A::privf
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for A::protStatf():
|
||||
string(%d) "/** My Doc Comment for A::protStatf */"
|
||||
|
||||
|
||||
---> Doc comment for A::finalStatPubf():
|
||||
string(%d) "/**
|
||||
|
||||
* My Doc Comment for A::finalStatPubf
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for B::f():
|
||||
bool(false)
|
||||
|
||||
|
||||
---> Doc comment for B::privf():
|
||||
string(%d) "/** *
|
||||
* My Doc Comment for B::privf
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for B::protStatf():
|
||||
string(%d) "/** My Doc Comment for B::protStatf
|
||||
|
||||
|
||||
|
||||
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for B::finalStatPubf():
|
||||
string(%d) "/**
|
||||
|
||||
* My Doc Comment for A::finalStatPubf
|
||||
*/"
|
||||
--UEXPECTF--
|
||||
---> Doc comment for A::f():
|
||||
unicode(%s) "/**
|
||||
* My Doc Comment for A::f
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for A::privf():
|
||||
unicode(%s) "/**
|
||||
* My Doc Comment for A::privf
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for A::protStatf():
|
||||
unicode(%s) "/** My Doc Comment for A::protStatf */"
|
||||
|
||||
|
||||
---> Doc comment for A::finalStatPubf():
|
||||
unicode(%s) "/**
|
||||
|
||||
* My Doc Comment for A::finalStatPubf
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for B::f():
|
||||
bool(false)
|
||||
|
||||
|
||||
---> Doc comment for B::privf():
|
||||
unicode(%s) "/** *
|
||||
* My Doc Comment for B::privf
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for B::protStatf():
|
||||
unicode(%s) "/** My Doc Comment for B::protStatf
|
||||
|
||||
|
||||
|
||||
|
||||
*/"
|
||||
|
||||
|
||||
---> Doc comment for B::finalStatPubf():
|
||||
unicode(%s) "/**
|
||||
|
||||
* My Doc Comment for A::finalStatPubf
|
||||
*/"
|
||||
@@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
ReflectionMethod::getDocComment() errors
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
class C { function f() {} }
|
||||
$rc = new ReflectionMethod('C::f');
|
||||
var_dump($rc->getDocComment(null));
|
||||
var_dump($rc->getDocComment('X'));
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Warning: Wrong parameter count for ReflectionFunctionAbstract::getDocComment() in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: Wrong parameter count for ReflectionFunctionAbstract::getDocComment() in %s on line %d
|
||||
NULL
|
||||
|
||||
244
ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt
Normal file
244
ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt
Normal file
@@ -0,0 +1,244 @@
|
||||
--TEST--
|
||||
ReflectionMethod::getModifiers()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function reflectMethodModifiers($class) {
|
||||
$classInfo = new reflectionClass($class);
|
||||
$methodArray = $classInfo->getMethods();
|
||||
|
||||
foreach ($methodArray as $method) {
|
||||
echo "Modifiers for method $method->class::$method->name():\n";
|
||||
var_dump($method->getModifiers());
|
||||
echo "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public function foo() {
|
||||
echo "Called foo()\n";
|
||||
}
|
||||
|
||||
static function stat() {
|
||||
echo "Called stat()\n";
|
||||
}
|
||||
|
||||
private function priv() {
|
||||
echo "Called priv()\n";
|
||||
}
|
||||
|
||||
protected function prot() {}
|
||||
|
||||
public final function fin() {}
|
||||
|
||||
public function __destruct() {}
|
||||
|
||||
public function __call($a, $b) {}
|
||||
|
||||
public function __clone() {}
|
||||
|
||||
public function __get($a) {}
|
||||
|
||||
public function __set($a, $b) {}
|
||||
|
||||
public function __unset($a) {}
|
||||
|
||||
public function __isset($a) {}
|
||||
|
||||
public function __tostring() {}
|
||||
|
||||
public function __sleep() {}
|
||||
|
||||
public function __wakeup() {}
|
||||
|
||||
public function __set_state() {}
|
||||
|
||||
public function __autoload() {}
|
||||
}
|
||||
|
||||
class DerivedClass extends TestClass {}
|
||||
|
||||
interface TestInterface {
|
||||
public function int();
|
||||
public function __clone();
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
public abstract function foo();
|
||||
}
|
||||
|
||||
|
||||
|
||||
reflectMethodModifiers("TestClass");
|
||||
reflectMethodModifiers("DerivedClass");
|
||||
reflectMethodModifiers("TestInterface");
|
||||
reflectMethodModifiers("AbstractClass");
|
||||
|
||||
echo "Wrong number of params:\n";
|
||||
$a = new ReflectionMethod('TestClass::foo');
|
||||
$a->getModifiers(1);
|
||||
|
||||
$a = new ReflectionMethod('ReflectionMethod::getModifiers');
|
||||
|
||||
echo "\nReflectionMethod::getModifiers() modifiers:\n";
|
||||
var_dump($a->getModifiers());
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Modifiers for method TestClass::foo():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method TestClass::stat():
|
||||
int(257)
|
||||
|
||||
|
||||
Modifiers for method TestClass::priv():
|
||||
int(66560)
|
||||
|
||||
|
||||
Modifiers for method TestClass::prot():
|
||||
int(66048)
|
||||
|
||||
|
||||
Modifiers for method TestClass::fin():
|
||||
int(65796)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__destruct():
|
||||
int(16640)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__call():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__clone():
|
||||
int(33024)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__get():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__set():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__unset():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__isset():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__tostring():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__sleep():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__wakeup():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__set_state():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method TestClass::__autoload():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::foo():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::stat():
|
||||
int(257)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::priv():
|
||||
int(66560)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::prot():
|
||||
int(66048)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::fin():
|
||||
int(65796)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__destruct():
|
||||
int(16640)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__call():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__clone():
|
||||
int(33024)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__get():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__set():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__unset():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__isset():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__tostring():
|
||||
int(256)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__sleep():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__wakeup():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__set_state():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method DerivedClass::__autoload():
|
||||
int(65792)
|
||||
|
||||
|
||||
Modifiers for method TestInterface::int():
|
||||
int(258)
|
||||
|
||||
|
||||
Modifiers for method TestInterface::__clone():
|
||||
int(258)
|
||||
|
||||
|
||||
Modifiers for method AbstractClass::foo():
|
||||
int(65794)
|
||||
|
||||
|
||||
Wrong number of params:
|
||||
|
||||
Warning: Wrong parameter count for ReflectionMethod::getModifiers() in %s on line %d
|
||||
|
||||
ReflectionMethod::getModifiers() modifiers:
|
||||
int(256)
|
||||
@@ -0,0 +1,89 @@
|
||||
--TEST--
|
||||
ReflectionMethod::getStaticVariables()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
public function foo() {
|
||||
static $c;
|
||||
static $a = 1;
|
||||
static $b = "hello";
|
||||
$d = 5;
|
||||
}
|
||||
|
||||
private function bar() {
|
||||
static $a = 1;
|
||||
}
|
||||
|
||||
public function noStatics() {
|
||||
$a = 54;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Public method:\n";
|
||||
$methodInfo = new ReflectionMethod('TestClass::foo');
|
||||
var_dump($methodInfo->getStaticVariables());
|
||||
|
||||
echo "\nPrivate method:\n";
|
||||
$methodInfo = new ReflectionMethod('TestClass::bar');
|
||||
var_dump($methodInfo->getStaticVariables());
|
||||
|
||||
echo "\nMethod with no static variables:\n";
|
||||
$methodInfo = new ReflectionMethod('TestClass::noStatics');
|
||||
var_dump($methodInfo->getStaticVariables());
|
||||
|
||||
echo "\nInternal Method:\n";
|
||||
$methodInfo = new ReflectionMethod('ReflectionClass::getName');
|
||||
var_dump($methodInfo->getStaticVariables());
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Public method:
|
||||
array(3) {
|
||||
["c"]=>
|
||||
NULL
|
||||
["a"]=>
|
||||
int(1)
|
||||
["b"]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
|
||||
Private method:
|
||||
array(1) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
Method with no static variables:
|
||||
array(0) {
|
||||
}
|
||||
|
||||
Internal Method:
|
||||
array(0) {
|
||||
}
|
||||
--UEXPECT--
|
||||
Public method:
|
||||
array(3) {
|
||||
[u"c"]=>
|
||||
NULL
|
||||
[u"a"]=>
|
||||
int(1)
|
||||
[u"b"]=>
|
||||
unicode(5) "hello"
|
||||
}
|
||||
|
||||
Private method:
|
||||
array(1) {
|
||||
[u"a"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
Method with no static variables:
|
||||
array(0) {
|
||||
}
|
||||
|
||||
Internal Method:
|
||||
array(0) {
|
||||
}
|
||||
98
ext/reflection/tests/ReflectionMethod_invokeArgs_basic.phpt
Normal file
98
ext/reflection/tests/ReflectionMethod_invokeArgs_basic.phpt
Normal file
@@ -0,0 +1,98 @@
|
||||
--TEST--
|
||||
ReflectionMethod::invokeArgs()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
public $prop = 2;
|
||||
|
||||
public function foo() {
|
||||
echo "Called foo(), property = $this->prop\n";
|
||||
var_dump($this);
|
||||
return "Return Val";
|
||||
}
|
||||
|
||||
public function willThrow() {
|
||||
throw new Exception("Called willThrow()");
|
||||
}
|
||||
|
||||
public function methodWithArgs($a, $b) {
|
||||
echo "Called methodWithArgs($a, $b)\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$testClassInstance = new TestClass();
|
||||
$testClassInstance->prop = "Hello";
|
||||
|
||||
$foo = new ReflectionMethod($testClassInstance, 'foo');
|
||||
$methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
|
||||
$methodThatThrows = new ReflectionMethod("TestClass::willThrow");
|
||||
|
||||
|
||||
echo "Public method:\n";
|
||||
|
||||
var_dump($foo->invokeArgs($testClassInstance, array()));
|
||||
var_dump($foo->invokeArgs($testClassInstance, array(true)));
|
||||
|
||||
echo "\nMethod with args:\n";
|
||||
|
||||
var_dump($methodWithArgs->invokeArgs($testClassInstance, array(1, "arg2")));
|
||||
var_dump($methodWithArgs->invokeArgs($testClassInstance, array(1, "arg2", 3)));
|
||||
|
||||
echo "\nMethod that throws an exception:\n";
|
||||
try {
|
||||
$methodThatThrows->invokeArgs($testClassInstance, array());
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Public method:
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
["prop"]=>
|
||||
string(5) "Hello"
|
||||
}
|
||||
string(10) "Return Val"
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
["prop"]=>
|
||||
string(5) "Hello"
|
||||
}
|
||||
string(10) "Return Val"
|
||||
|
||||
Method with args:
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
|
||||
Method that throws an exception:
|
||||
string(18) "Called willThrow()"
|
||||
--UEXPECTF--
|
||||
Public method:
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
[u"prop"]=>
|
||||
unicode(5) "Hello"
|
||||
}
|
||||
unicode(10) "Return Val"
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
[u"prop"]=>
|
||||
unicode(5) "Hello"
|
||||
}
|
||||
unicode(10) "Return Val"
|
||||
|
||||
Method with args:
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
|
||||
Method that throws an exception:
|
||||
unicode(18) "Called willThrow()"
|
||||
38
ext/reflection/tests/ReflectionMethod_invokeArgs_error1.phpt
Normal file
38
ext/reflection/tests/ReflectionMethod_invokeArgs_error1.phpt
Normal file
@@ -0,0 +1,38 @@
|
||||
--TEST--
|
||||
ReflectionMethod:invokeArgs() errors
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
|
||||
public function methodWithArgs($a, $b) {
|
||||
echo "Called methodWithArgs($a, $b)\n";
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
abstract function foo();
|
||||
}
|
||||
|
||||
$methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
|
||||
|
||||
$testClassInstance = new TestClass();
|
||||
|
||||
echo "\nMethod with args:\n";
|
||||
var_dump($methodWithArgs->invokeArgs($testClassInstance, array()));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Method with args:
|
||||
|
||||
Warning: Missing argument 1 for TestClass::methodWithArgs() in %s on line %d
|
||||
|
||||
Warning: Missing argument 2 for TestClass::methodWithArgs() in %s on line %d
|
||||
|
||||
Notice: Undefined variable: a in %s on line %d
|
||||
|
||||
Notice: Undefined variable: b in %s on line %d
|
||||
Called methodWithArgs(, )
|
||||
NULL
|
||||
29
ext/reflection/tests/ReflectionMethod_invokeArgs_error2.phpt
Normal file
29
ext/reflection/tests/ReflectionMethod_invokeArgs_error2.phpt
Normal file
@@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
ReflectionMethod::invokeArgs() further errors
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
|
||||
public function foo() {
|
||||
echo "Called foo()\n";
|
||||
var_dump($this);
|
||||
return "Return Val";
|
||||
}
|
||||
}
|
||||
|
||||
$foo = new ReflectionMethod('TestClass', 'foo');
|
||||
|
||||
$testClassInstance = new TestClass();
|
||||
|
||||
try {
|
||||
var_dump($foo->invokeArgs($testClassInstance, true));
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Catchable fatal error: Argument 2 passed to ReflectionMethod::invokeArgs() must be an array, boolean given in %s on line %d
|
||||
159
ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt
Normal file
159
ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt
Normal file
@@ -0,0 +1,159 @@
|
||||
--TEST--
|
||||
ReflectionMethod::invokeArgs() further errors
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
public $prop = 2;
|
||||
|
||||
public function foo() {
|
||||
echo "Called foo(), property = $this->prop\n";
|
||||
var_dump($this);
|
||||
return "Return Val";
|
||||
}
|
||||
|
||||
public static function staticMethod() {
|
||||
echo "Called staticMethod()\n";
|
||||
var_dump($this);
|
||||
}
|
||||
|
||||
private static function privateMethod() {
|
||||
echo "Called privateMethod()\n";
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
abstract function foo();
|
||||
}
|
||||
|
||||
$testClassInstance = new TestClass();
|
||||
$testClassInstance->prop = "Hello";
|
||||
|
||||
$foo = new ReflectionMethod($testClassInstance, 'foo');
|
||||
$staticMethod = new ReflectionMethod('TestClass::staticMethod');
|
||||
$privateMethod = new ReflectionMethod("TestClass::privateMethod");
|
||||
|
||||
echo "Wrong number of parameters:\n";
|
||||
var_dump($foo->invokeArgs());
|
||||
var_dump($foo->invokeArgs(true));
|
||||
|
||||
echo "\nNon-instance:\n";
|
||||
try {
|
||||
var_dump($foo->invokeArgs(new stdClass(), array()));
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
echo "\nNon-object:\n";
|
||||
var_dump($foo->invokeArgs(true, array()));
|
||||
|
||||
echo "\nStatic method:\n";
|
||||
|
||||
var_dump($staticMethod->invokeArgs());
|
||||
var_dump($staticMethod->invokeArgs(true));
|
||||
var_dump($staticMethod->invokeArgs(true, array()));
|
||||
var_dump($staticMethod->invokeArgs(null, array()));
|
||||
|
||||
echo "\nPrivate method:\n";
|
||||
try {
|
||||
var_dump($privateMethod->invokeArgs($testClassInstance, array()));
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
echo "\nAbstract method:\n";
|
||||
$abstractMethod = new ReflectionMethod("AbstractClass::foo");
|
||||
try {
|
||||
$abstractMethod->invokeArgs($testClassInstance, array());
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
try {
|
||||
$abstractMethod->invokeArgs(true);
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Wrong number of parameters:
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Non-instance:
|
||||
string(72) "Given object is not an instance of the class this method was declared in"
|
||||
|
||||
Non-object:
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %s on line %d
|
||||
NULL
|
||||
|
||||
Static method:
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %s on line %d
|
||||
NULL
|
||||
Called staticMethod()
|
||||
|
||||
Notice: Undefined variable: this in %s on line %d
|
||||
NULL
|
||||
NULL
|
||||
|
||||
Private method:
|
||||
string(84) "Trying to invoke private method TestClass::privateMethod from scope ReflectionMethod"
|
||||
|
||||
Abstract method:
|
||||
string(51) "Trying to invoke abstract method AbstractClass::foo"
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
|
||||
--UEXPECTF--
|
||||
Wrong number of parameters:
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
NULL
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
NULL
|
||||
|
||||
Non-instance:
|
||||
unicode(72) "Given object is not an instance of the class this method was declared in"
|
||||
|
||||
Non-object:
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
NULL
|
||||
|
||||
Static method:
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
NULL
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
NULL
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
NULL
|
||||
Called staticMethod()
|
||||
|
||||
Notice: Undefined variable: this in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
NULL
|
||||
NULL
|
||||
|
||||
Private method:
|
||||
unicode(84) "Trying to invoke private method TestClass::privateMethod from scope ReflectionMethod"
|
||||
|
||||
Abstract method:
|
||||
unicode(51) "Trying to invoke abstract method AbstractClass::foo"
|
||||
|
||||
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %sReflectionMethod_invokeArgs_error3.php on line %d
|
||||
148
ext/reflection/tests/ReflectionMethod_invoke_basic.phpt
Normal file
148
ext/reflection/tests/ReflectionMethod_invoke_basic.phpt
Normal file
@@ -0,0 +1,148 @@
|
||||
--TEST--
|
||||
ReflectionMethod::invoke()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
public $prop = 2;
|
||||
|
||||
public function foo() {
|
||||
echo "Called foo(), property = $this->prop\n";
|
||||
var_dump($this);
|
||||
return "Return Val";
|
||||
}
|
||||
|
||||
public function willThrow() {
|
||||
throw new Exception("Called willThrow()");
|
||||
}
|
||||
|
||||
public function methodWithArgs($a, $b) {
|
||||
echo "Called methodWithArgs($a, $b)\n";
|
||||
}
|
||||
|
||||
public static function staticMethod() {
|
||||
echo "Called staticMethod()\n";
|
||||
var_dump($this);
|
||||
}
|
||||
|
||||
private static function privateMethod() {
|
||||
echo "Called privateMethod()\n";
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
abstract function foo();
|
||||
}
|
||||
|
||||
$foo = new ReflectionMethod('TestClass', 'foo');
|
||||
$methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
|
||||
$staticMethod = new ReflectionMethod('TestClass::staticMethod');
|
||||
$privateMethod = new ReflectionMethod("TestClass::privateMethod");
|
||||
$methodThatThrows = new ReflectionMethod("TestClass::willThrow");
|
||||
|
||||
$testClassInstance = new TestClass();
|
||||
$testClassInstance->prop = "Hello";
|
||||
|
||||
echo "Public method:\n";
|
||||
|
||||
var_dump($foo->invoke($testClassInstance));
|
||||
|
||||
var_dump($foo->invoke($testClassInstance, true));
|
||||
|
||||
echo "\nMethod with args:\n";
|
||||
|
||||
var_dump($methodWithArgs->invoke($testClassInstance, 1, "arg2"));
|
||||
var_dump($methodWithArgs->invoke($testClassInstance, 1, "arg2", 3));
|
||||
|
||||
echo "\nStatic method:\n";
|
||||
|
||||
var_dump($staticMethod->invoke());
|
||||
var_dump($staticMethod->invoke(true));
|
||||
var_dump($staticMethod->invoke(new stdClass()));
|
||||
|
||||
echo "\nMethod that throws an exception:\n";
|
||||
try {
|
||||
var_dump($methodThatThrows->invoke($testClassInstance));
|
||||
} catch (Exception $exc) {
|
||||
var_dump($exc->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Public method:
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
["prop"]=>
|
||||
string(5) "Hello"
|
||||
}
|
||||
string(10) "Return Val"
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
["prop"]=>
|
||||
string(5) "Hello"
|
||||
}
|
||||
string(10) "Return Val"
|
||||
|
||||
Method with args:
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
|
||||
Static method:
|
||||
|
||||
Warning: Invoke() expects at least one parameter, none given in %s on line %d
|
||||
bool(false)
|
||||
Called staticMethod()
|
||||
|
||||
Notice: Undefined variable: this in %s on line %d
|
||||
NULL
|
||||
NULL
|
||||
Called staticMethod()
|
||||
|
||||
Notice: Undefined variable: this in %s on line %d
|
||||
NULL
|
||||
NULL
|
||||
|
||||
Method that throws an exception:
|
||||
string(18) "Called willThrow()"
|
||||
--UEXPECTF--
|
||||
Public method:
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
[u"prop"]=>
|
||||
unicode(5) "Hello"
|
||||
}
|
||||
unicode(10) "Return Val"
|
||||
Called foo(), property = Hello
|
||||
object(TestClass)#%d (1) {
|
||||
[u"prop"]=>
|
||||
unicode(5) "Hello"
|
||||
}
|
||||
unicode(10) "Return Val"
|
||||
|
||||
Method with args:
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
Called methodWithArgs(1, arg2)
|
||||
NULL
|
||||
|
||||
Static method:
|
||||
|
||||
Warning: Invoke() expects at least one parameter, none given in %sReflectionMethod_invoke_basic.php on line %d
|
||||
bool(false)
|
||||
Called staticMethod()
|
||||
|
||||
Notice: Undefined variable: this in %sReflectionMethod_invoke_basic.php on line %d
|
||||
NULL
|
||||
NULL
|
||||
Called staticMethod()
|
||||
|
||||
Notice: Undefined variable: this in %sReflectionMethod_invoke_basic.php on line %d
|
||||
NULL
|
||||
NULL
|
||||
|
||||
Method that throws an exception:
|
||||
unicode(18) "Called willThrow()"
|
||||
85
ext/reflection/tests/ReflectionMethod_invoke_error1.phpt
Normal file
85
ext/reflection/tests/ReflectionMethod_invoke_error1.phpt
Normal file
@@ -0,0 +1,85 @@
|
||||
--TEST--
|
||||
ReflectionMethod::invoke() errors
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
public $prop = 2;
|
||||
|
||||
public function foo() {
|
||||
echo "Called foo(), property = $this->prop\n";
|
||||
var_dump($this);
|
||||
return "Return Val";
|
||||
}
|
||||
|
||||
private static function privateMethod() {
|
||||
echo "Called privateMethod()\n";
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
abstract function foo();
|
||||
}
|
||||
|
||||
$foo = new ReflectionMethod('TestClass', 'foo');
|
||||
$privateMethod = new ReflectionMethod("TestClass::privateMethod");
|
||||
|
||||
$testClassInstance = new TestClass();
|
||||
$testClassInstance->prop = "Hello";
|
||||
|
||||
echo "invoke() on a non-object:\n";
|
||||
try {
|
||||
var_dump($foo->invoke(true));
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
echo "\ninvoke() on a non-instance:\n";
|
||||
try {
|
||||
var_dump($foo->invoke(new stdClass()));
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
echo "\nPrivate method:\n";
|
||||
try {
|
||||
var_dump($privateMethod->invoke($testClassInstance));
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
echo "\nAbstract method:\n";
|
||||
$abstractMethod = new ReflectionMethod("AbstractClass::foo");
|
||||
try {
|
||||
$abstractMethod->invoke(true);
|
||||
} catch (ReflectionException $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
invoke() on a non-object:
|
||||
string(29) "Non-object passed to Invoke()"
|
||||
|
||||
invoke() on a non-instance:
|
||||
string(72) "Given object is not an instance of the class this method was declared in"
|
||||
|
||||
Private method:
|
||||
string(86) "Trying to invoke private method TestClass::privateMethod() from scope ReflectionMethod"
|
||||
|
||||
Abstract method:
|
||||
string(53) "Trying to invoke abstract method AbstractClass::foo()"
|
||||
--UEXPECT--
|
||||
invoke() on a non-object:
|
||||
unicode(29) "Non-object passed to Invoke()"
|
||||
|
||||
invoke() on a non-instance:
|
||||
unicode(72) "Given object is not an instance of the class this method was declared in"
|
||||
|
||||
Private method:
|
||||
unicode(86) "Trying to invoke private method TestClass::privateMethod() from scope ReflectionMethod"
|
||||
|
||||
Abstract method:
|
||||
unicode(53) "Trying to invoke abstract method AbstractClass::foo()"
|
||||
34
ext/reflection/tests/ReflectionMethod_invoke_error2.phpt
Normal file
34
ext/reflection/tests/ReflectionMethod_invoke_error2.phpt
Normal file
@@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
ReflectionMethod::invoke() further errors
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
|
||||
public function methodWithArgs($a, $b) {
|
||||
echo "Called methodWithArgs($a, $b)\n";
|
||||
}
|
||||
}
|
||||
|
||||
$methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
|
||||
|
||||
$testClassInstance = new TestClass();
|
||||
|
||||
echo "\nMethod with args:\n";
|
||||
var_dump($methodWithArgs->invoke($testClassInstance));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Method with args:
|
||||
|
||||
Warning: Missing argument 1 for TestClass::methodWithArgs() in %s on line %d
|
||||
|
||||
Warning: Missing argument 2 for TestClass::methodWithArgs() in %s on line %d
|
||||
|
||||
Notice: Undefined variable: a in %s on line %d
|
||||
|
||||
Notice: Undefined variable: b in %s on line %d
|
||||
Called methodWithArgs(, )
|
||||
NULL
|
||||
@@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
ReflectionMethod::returnsReference()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('reflection') or die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class TestClass {
|
||||
public function &foo() {
|
||||
}
|
||||
|
||||
private function bar() {
|
||||
}
|
||||
}
|
||||
|
||||
$methodInfo = new ReflectionMethod('TestClass::foo');
|
||||
var_dump($methodInfo->returnsReference());
|
||||
|
||||
$methodInfo = new ReflectionMethod('TestClass::bar');
|
||||
var_dump($methodInfo->returnsReference());
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
||||
bool(false)
|
||||
Reference in New Issue
Block a user