Browse Source
Reflection tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit).
PHP-5.2.1RC1
Reflection tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit).
PHP-5.2.1RC1
56 changed files with 4908 additions and 0 deletions
-
198ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt
-
45ext/reflection/tests/ReflectionClass_getDefaultProperties_002.phpt
-
98ext/reflection/tests/ReflectionClass_getDocComment_001.phpt
-
27ext/reflection/tests/ReflectionClass_getDocComment_002.phpt
-
311ext/reflection/tests/ReflectionClass_getInterfaces_001.phpt
-
53ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt
-
69ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt
-
28ext/reflection/tests/ReflectionClass_getInterfaces_004.phpt
-
168ext/reflection/tests/ReflectionClass_getMethod_001.phpt
-
74ext/reflection/tests/ReflectionClass_getMethod_002.phpt
-
140ext/reflection/tests/ReflectionClass_getMethods_001.phpt
-
18ext/reflection/tests/ReflectionClass_getMethods_002.phpt
-
191ext/reflection/tests/ReflectionClass_getMethods_003.phpt
-
38ext/reflection/tests/ReflectionClass_getParentClass_001.phpt
-
126ext/reflection/tests/ReflectionClass_getProperties_001.phpt
-
17ext/reflection/tests/ReflectionClass_getProperties_002.phpt
-
189ext/reflection/tests/ReflectionClass_getProperties_003.phpt
-
146ext/reflection/tests/ReflectionClass_getProperty_001.phpt
-
72ext/reflection/tests/ReflectionClass_getProperty_002.phpt
-
251ext/reflection/tests/ReflectionClass_getProperty_003.phpt
-
251ext/reflection/tests/ReflectionClass_getProperty_004.phpt
-
67ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001.phpt
-
52ext/reflection/tests/ReflectionClass_getStaticPropertyValue_002.phpt
-
36ext/reflection/tests/ReflectionClass_hasConstant_001.phpt
-
40ext/reflection/tests/ReflectionClass_hasConstant_002.phpt
-
75ext/reflection/tests/ReflectionClass_hasMethod_001.phpt
-
40ext/reflection/tests/ReflectionClass_hasMethod_002.phpt
-
75ext/reflection/tests/ReflectionClass_hasProperty_001.phpt
-
40ext/reflection/tests/ReflectionClass_hasProperty_002.phpt
-
155ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt
-
75ext/reflection/tests/ReflectionClass_isIterateable_001.phpt
-
49ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt
-
44ext/reflection/tests/ReflectionClass_modifiers_001.phpt
-
28ext/reflection/tests/ReflectionClass_modifiers_002.phpt
-
98ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt
-
20ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt
-
98ext/reflection/tests/ReflectionClass_newInstance_001.phpt
-
77ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt
-
60ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt
-
224ext/reflection/tests/ReflectionClass_toString_001.phpt
-
123ext/reflection/tests/ReflectionClass_toString_002.phpt
-
123ext/reflection/tests/ReflectionClass_toString_003.phpt
-
67ext/reflection/tests/ReflectionFunction_001.phpt
-
23ext/reflection/tests/ReflectionFunction_construct.001.phpt
-
41ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt
-
18ext/reflection/tests/ReflectionFunction_getFileName.001.phpt
-
39ext/reflection/tests/ReflectionFunction_getFileName.002.phpt
-
100ext/reflection/tests/ReflectionMethod_006.phpt
-
103ext/reflection/tests/ReflectionMethod_constructor_error1.phpt
-
37ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
-
48ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt
-
80ext/reflection/tests/ReflectionParameter_001.phpt
-
80ext/reflection/tests/ReflectionParameter_002.phpt
-
88ext/reflection/tests/ReflectionParameter_003.phpt
-
66ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt
-
9ext/reflection/tests/included4.inc
@ -0,0 +1,198 @@ |
|||
--TEST-- |
|||
ReflectionClass::getDefaultProperties(), ReflectionClass::getStaticProperties() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
|
|||
class A { |
|||
static public $statPubC = "stat pubC in A"; |
|||
static protected $statProtC = "stat protC in A"; |
|||
static private $statPrivC = "stat privC in A"; |
|||
|
|||
static public $statPubA = "stat pubA in A"; |
|||
static protected $statProtA = "stat protA in A"; |
|||
static private $statPrivA = "stat privA in A"; |
|||
|
|||
public $pubC = "pubC in A"; |
|||
protected $protC = "protC in A"; |
|||
private $privC = "privC in A"; |
|||
|
|||
public $pubA = "pubA in A"; |
|||
protected $protA = "protA in A"; |
|||
private $privA = "privA in A"; |
|||
} |
|||
|
|||
class B extends A { |
|||
static public $statPubC = "stat pubC in B"; |
|||
static protected $statProtC = "stat protC in B"; |
|||
static private $statPrivC = "stat privC in B"; |
|||
|
|||
static public $statPubB = "stat pubB in B"; |
|||
static protected $statProtB = "stat protB in B"; |
|||
static private $statPrivB = "stat privB in B"; |
|||
|
|||
public $pubC = "pubC in B"; |
|||
protected $protC = "protC in B"; |
|||
private $privC = "privC in B"; |
|||
|
|||
public $pubB = "pubB in B"; |
|||
protected $protB = "protB in B"; |
|||
private $privB = "privB in B"; |
|||
} |
|||
|
|||
class C extends B { |
|||
static public $statPubC = "stat pubC in C"; |
|||
static protected $statProtC = "stat protC in C"; |
|||
static private $statPrivC = "stat privC in C"; |
|||
|
|||
public $pubC = "pubC in C"; |
|||
protected $protC = "protC in C"; |
|||
private $privC = "privC in C"; |
|||
} |
|||
|
|||
class X { |
|||
static public $statPubC = "stat pubC in X"; |
|||
static protected $statProtC = "stat protC in X"; |
|||
static private $statPrivC = "stat privC in X"; |
|||
|
|||
public $pubC = "pubC in X"; |
|||
protected $protC = "protC in X"; |
|||
private $privC = "privC in X"; |
|||
} |
|||
|
|||
$classes = array('A', 'B', 'C', 'X'); |
|||
foreach ($classes as $class) { |
|||
$rc = new ReflectionClass($class); |
|||
echo "\n\n---- Static properties in $class ----\n"; |
|||
print_r($rc->getStaticProperties()); |
|||
echo "\n\n---- Default properties in $class ----\n"; |
|||
print_r($rc->getDefaultProperties()); |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
---- Static properties in A ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in A |
|||
[statProtC] => stat protC in A |
|||
[statPrivC] => stat privC in A |
|||
[statPubA] => stat pubA in A |
|||
[statProtA] => stat protA in A |
|||
[statPrivA] => stat privA in A |
|||
) |
|||
|
|||
|
|||
---- Default properties in A ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in A |
|||
[statProtC] => stat protC in A |
|||
[statPrivC] => stat privC in A |
|||
[statPubA] => stat pubA in A |
|||
[statProtA] => stat protA in A |
|||
[statPrivA] => stat privA in A |
|||
[pubC] => pubC in A |
|||
[protC] => protC in A |
|||
[privC] => privC in A |
|||
[pubA] => pubA in A |
|||
[protA] => protA in A |
|||
[privA] => privA in A |
|||
) |
|||
|
|||
|
|||
---- Static properties in B ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in B |
|||
[statProtC] => stat protC in B |
|||
[statPrivC] => stat privC in A |
|||
[statPubB] => stat pubB in B |
|||
[statProtB] => stat protB in B |
|||
[statPrivB] => stat privB in B |
|||
[statPubA] => stat pubA in A |
|||
[statProtA] => stat protA in A |
|||
[statPrivA] => stat privA in A |
|||
) |
|||
|
|||
|
|||
---- Default properties in B ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in B |
|||
[statProtC] => stat protC in B |
|||
[statPrivC] => stat privC in B |
|||
[statPubB] => stat pubB in B |
|||
[statProtB] => stat protB in B |
|||
[statPrivB] => stat privB in B |
|||
[statPubA] => stat pubA in A |
|||
[statProtA] => stat protA in A |
|||
[pubC] => pubC in B |
|||
[protC] => protC in B |
|||
[privC] => privC in B |
|||
[pubB] => pubB in B |
|||
[protB] => protB in B |
|||
[privB] => privB in B |
|||
[pubA] => pubA in A |
|||
[protA] => protA in A |
|||
) |
|||
|
|||
|
|||
---- Static properties in C ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in C |
|||
[statProtC] => stat protC in C |
|||
[statPrivC] => stat privC in A |
|||
[statPubB] => stat pubB in B |
|||
[statProtB] => stat protB in B |
|||
[statPrivB] => stat privB in B |
|||
[statPubA] => stat pubA in A |
|||
[statProtA] => stat protA in A |
|||
[statPrivA] => stat privA in A |
|||
) |
|||
|
|||
|
|||
---- Default properties in C ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in C |
|||
[statProtC] => stat protC in C |
|||
[statPrivC] => stat privC in C |
|||
[statPubB] => stat pubB in B |
|||
[statProtB] => stat protB in B |
|||
[statPubA] => stat pubA in A |
|||
[statProtA] => stat protA in A |
|||
[pubC] => pubC in C |
|||
[protC] => protC in C |
|||
[privC] => privC in C |
|||
[pubB] => pubB in B |
|||
[protB] => protB in B |
|||
[pubA] => pubA in A |
|||
[protA] => protA in A |
|||
) |
|||
|
|||
|
|||
---- Static properties in X ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in X |
|||
[statProtC] => stat protC in X |
|||
[statPrivC] => stat privC in X |
|||
) |
|||
|
|||
|
|||
---- Default properties in X ---- |
|||
Array |
|||
( |
|||
[statPubC] => stat pubC in X |
|||
[statProtC] => stat protC in X |
|||
[statPrivC] => stat privC in X |
|||
[pubC] => pubC in X |
|||
[protC] => protC in X |
|||
[privC] => privC in X |
|||
) |
|||
|
|||
@ -0,0 +1,45 @@ |
|||
--TEST-- |
|||
ReflectionClass::getDefaultProperties(), ReflectionClass::getStaticProperties() - wrong param count |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
interface I {} |
|||
class C implements I {} |
|||
$rc = new ReflectionClass('C'); |
|||
var_dump($rc->getDefaultProperties(null)); |
|||
var_dump($rc->getDefaultProperties('X')); |
|||
var_dump($rc->getDefaultProperties(true)); |
|||
var_dump($rc->getDefaultProperties(array(1,2,3))); |
|||
var_dump($rc->getStaticProperties(null)); |
|||
var_dump($rc->getStaticProperties('X')); |
|||
var_dump($rc->getStaticProperties(true)); |
|||
var_dump($rc->getStaticProperties(array(1,2,3))); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 5 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 6 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 7 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 8 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 9 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 10 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 11 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 12 |
|||
NULL |
|||
@ -0,0 +1,98 @@ |
|||
--TEST-- |
|||
ReflectionClass::getDocComment() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
/** |
|||
|
|||
|
|||
My |
|||
Doc |
|||
* Comment |
|||
for A |
|||
|
|||
* */ |
|||
class A {} |
|||
|
|||
/** My DocComment for B */ |
|||
class B extends A { } |
|||
|
|||
class C extends B {} |
|||
|
|||
/** |
|||
* Interface doc comment |
|||
*/ |
|||
|
|||
|
|||
|
|||
|
|||
interface I {} |
|||
|
|||
/*.* |
|||
* Not a doc comment |
|||
*/ |
|||
class D implements I {} |
|||
|
|||
/**** Not a doc comment */ |
|||
class E extends C implements I {} {} |
|||
|
|||
/**?** Not a doc comment */ |
|||
class F extends C implements I {} {} |
|||
|
|||
/** ** Doc comment for G */ |
|||
final class G extends C implements I {} {} |
|||
|
|||
$classes = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'I'); |
|||
foreach ($classes as $class) { |
|||
echo "\n\n---> Doc comment for class $class:\n"; |
|||
$rc = new ReflectionClass($class); |
|||
var_dump($rc->getDocComment()); |
|||
} |
|||
|
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
|
|||
---> Doc comment for class A: |
|||
string(%d) "/** |
|||
|
|||
|
|||
My |
|||
Doc |
|||
* Comment |
|||
for A |
|||
|
|||
* */" |
|||
|
|||
|
|||
---> Doc comment for class B: |
|||
string(26) "/** My DocComment for B */" |
|||
|
|||
|
|||
---> Doc comment for class C: |
|||
bool(false) |
|||
|
|||
|
|||
---> Doc comment for class D: |
|||
bool(false) |
|||
|
|||
|
|||
---> Doc comment for class E: |
|||
bool(false) |
|||
|
|||
|
|||
---> Doc comment for class F: |
|||
bool(false) |
|||
|
|||
|
|||
---> Doc comment for class G: |
|||
string(27) "/** ** Doc comment for G */" |
|||
|
|||
|
|||
---> Doc comment for class I: |
|||
string(%d) "/** |
|||
* Interface doc comment |
|||
*/" |
|||
@ -0,0 +1,27 @@ |
|||
--TEST-- |
|||
ReflectionClass::getDocComment() - bad params |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C {} |
|||
$rc = new ReflectionClass('C'); |
|||
var_dump($rc->getDocComment(null)); |
|||
var_dump($rc->getDocComment('X')); |
|||
var_dump($rc->getDocComment(true)); |
|||
var_dump($rc->getDocComment(array(1,2,3))); |
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 4 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 5 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 6 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 7 |
|||
NULL |
|||
@ -0,0 +1,311 @@ |
|||
--TEST-- |
|||
ReflectionClass::getInterfaces() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A0 {} |
|||
class B0 extends A0 {} |
|||
abstract class A1 {} |
|||
class B1 extends A1 {} |
|||
|
|||
interface I0 {} |
|||
interface I1 {} |
|||
interface I2 {} |
|||
interface I3 {} |
|||
interface I4 extends I3 {} |
|||
interface I5 extends I4 {} |
|||
interface I6 extends I5, I1, I2 {} |
|||
interface I7 extends I6 {} |
|||
|
|||
class C0 implements I0 {} |
|||
class C1 implements I1, I3 {} |
|||
class C2 extends C1 {} |
|||
class C3 extends C2 implements I1 {} |
|||
class C4 extends C3 implements I2 {} |
|||
class C5 extends C4 implements I7 {} |
|||
class C6 implements I1, I2, I3, I4, I5, I6, I7 {} |
|||
|
|||
|
|||
$classes = array( 'A0', 'A1', 'B0', 'B1', |
|||
'I0', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', |
|||
'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6' ); |
|||
|
|||
foreach ($classes as $class) { |
|||
echo "---( Interfaces implemented by $class )---\n "; |
|||
$rc = new ReflectionClass($class); |
|||
$interfaces = $rc->getInterfaces(); |
|||
// Sort interfaces so that tests do not fail because of wrong order. |
|||
ksort($interfaces); |
|||
print_r($interfaces); |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
---( Interfaces implemented by A0 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by A1 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by B0 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by B1 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by I0 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by I1 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by I2 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by I3 )--- |
|||
Array |
|||
( |
|||
) |
|||
---( Interfaces implemented by I4 )--- |
|||
Array |
|||
( |
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by I5 )--- |
|||
Array |
|||
( |
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
[I4] => ReflectionClass Object |
|||
( |
|||
[name] => I4 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by I6 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I2] => ReflectionClass Object |
|||
( |
|||
[name] => I2 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
[I4] => ReflectionClass Object |
|||
( |
|||
[name] => I4 |
|||
) |
|||
|
|||
[I5] => ReflectionClass Object |
|||
( |
|||
[name] => I5 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by I7 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I2] => ReflectionClass Object |
|||
( |
|||
[name] => I2 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
[I4] => ReflectionClass Object |
|||
( |
|||
[name] => I4 |
|||
) |
|||
|
|||
[I5] => ReflectionClass Object |
|||
( |
|||
[name] => I5 |
|||
) |
|||
|
|||
[I6] => ReflectionClass Object |
|||
( |
|||
[name] => I6 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by C0 )--- |
|||
Array |
|||
( |
|||
[I0] => ReflectionClass Object |
|||
( |
|||
[name] => I0 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by C1 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by C2 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by C3 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by C4 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I2] => ReflectionClass Object |
|||
( |
|||
[name] => I2 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by C5 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I2] => ReflectionClass Object |
|||
( |
|||
[name] => I2 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
[I4] => ReflectionClass Object |
|||
( |
|||
[name] => I4 |
|||
) |
|||
|
|||
[I5] => ReflectionClass Object |
|||
( |
|||
[name] => I5 |
|||
) |
|||
|
|||
[I6] => ReflectionClass Object |
|||
( |
|||
[name] => I6 |
|||
) |
|||
|
|||
[I7] => ReflectionClass Object |
|||
( |
|||
[name] => I7 |
|||
) |
|||
|
|||
) |
|||
---( Interfaces implemented by C6 )--- |
|||
Array |
|||
( |
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I2] => ReflectionClass Object |
|||
( |
|||
[name] => I2 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
[I4] => ReflectionClass Object |
|||
( |
|||
[name] => I4 |
|||
) |
|||
|
|||
[I5] => ReflectionClass Object |
|||
( |
|||
[name] => I5 |
|||
) |
|||
|
|||
[I6] => ReflectionClass Object |
|||
( |
|||
[name] => I6 |
|||
) |
|||
|
|||
[I7] => ReflectionClass Object |
|||
( |
|||
[name] => I7 |
|||
) |
|||
|
|||
) |
|||
@ -0,0 +1,53 @@ |
|||
--TEST-- |
|||
ReflectionClass::getInterfaces() - interface ordering. |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
interface I1 {} |
|||
interface I2 {} |
|||
interface I3 {} |
|||
interface I4 extends I3 {} |
|||
interface I5 extends I4 {} |
|||
interface I6 extends I5, I1, I2 {} |
|||
interface I7 extends I6 {} |
|||
|
|||
$rc = new ReflectionClass('I7'); |
|||
$interfaces = $rc->getInterfaces(); |
|||
print_r($interfaces); |
|||
?> |
|||
--EXPECTF-- |
|||
Array |
|||
( |
|||
[I6] => ReflectionClass Object |
|||
( |
|||
[name] => I6 |
|||
) |
|||
|
|||
[I2] => ReflectionClass Object |
|||
( |
|||
[name] => I2 |
|||
) |
|||
|
|||
[I1] => ReflectionClass Object |
|||
( |
|||
[name] => I1 |
|||
) |
|||
|
|||
[I4] => ReflectionClass Object |
|||
( |
|||
[name] => I4 |
|||
) |
|||
|
|||
[I3] => ReflectionClass Object |
|||
( |
|||
[name] => I3 |
|||
) |
|||
|
|||
[I5] => ReflectionClass Object |
|||
( |
|||
[name] => I5 |
|||
) |
|||
|
|||
) |
|||
@ -0,0 +1,69 @@ |
|||
--TEST-- |
|||
ReflectionClass::getInterfaces() - odd ampersand behaviour. |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
echo "An object is in an array and is referenced. As expected, var_dumping the array shows '&':\n"; |
|||
$a = array(new stdclass); |
|||
$b =& $a[0]; |
|||
var_dump($a); |
|||
|
|||
echo "Naturally, this remains true if we modify the object:\n"; |
|||
$a[0]->x = 1; |
|||
var_dump($a); |
|||
|
|||
|
|||
echo "\n\nObtain the array of interfaces implemented by C.\n"; |
|||
interface I {} |
|||
class C implements I {} |
|||
$rc = new ReflectionClass('C'); |
|||
$a = $rc->getInterfaces(); |
|||
echo "The result is an array in which each element is an object (an instance of ReflectionClass)\n"; |
|||
echo "Var_dumping this array shows that the elements are referenced. By what?\n"; |
|||
var_dump($a); |
|||
|
|||
echo "Modify the object, and it is apparently no longer referenced.\n"; |
|||
$a['I']->x = 1; |
|||
var_dump($a); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
An object is in an array and is referenced. As expected, var_dumping the array shows '&': |
|||
array(1) { |
|||
[0]=> |
|||
&object(stdClass)#%d (0) { |
|||
} |
|||
} |
|||
Naturally, this remains true if we modify the object: |
|||
array(1) { |
|||
[0]=> |
|||
&object(stdClass)#%d (1) { |
|||
["x"]=> |
|||
int(1) |
|||
} |
|||
} |
|||
|
|||
|
|||
Obtain the array of interfaces implemented by C. |
|||
The result is an array in which each element is an object (an instance of ReflectionClass) |
|||
Var_dumping this array shows that the elements are referenced. By what? |
|||
array(1) { |
|||
["I"]=> |
|||
&object(ReflectionClass)#%d (1) { |
|||
["name"]=> |
|||
string(1) "I" |
|||
} |
|||
} |
|||
Modify the object, and it is apparently no longer referenced. |
|||
array(1) { |
|||
["I"]=> |
|||
object(ReflectionClass)#%d (2) { |
|||
["name"]=> |
|||
string(1) "I" |
|||
["x"]=> |
|||
int(1) |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
--TEST-- |
|||
ReflectionClass::getInterfaces() - wrong param count |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
interface I {} |
|||
class C implements I {} |
|||
$rc = new ReflectionClass('C'); |
|||
var_dump($rc->getInterfaces(null)); |
|||
var_dump($rc->getInterfaces('X')); |
|||
var_dump($rc->getInterfaces(true)); |
|||
var_dump($rc->getInterfaces(array(1,2,3))); |
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 5 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 6 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 7 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 8 |
|||
NULL |
|||
@ -0,0 +1,168 @@ |
|||
--TEST-- |
|||
ReflectionClass::getMethod() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class pubf { |
|||
public function f() {} |
|||
static public function s() {} |
|||
} |
|||
class subpubf extends pubf { |
|||
} |
|||
|
|||
class protf { |
|||
protected function f() {} |
|||
static protected function s() {} |
|||
} |
|||
class subprotf extends protf { |
|||
} |
|||
|
|||
class privf { |
|||
private function f() {} |
|||
static private function s() {} |
|||
} |
|||
class subprivf extends privf { |
|||
} |
|||
|
|||
$classes = array("pubf", "subpubf", "protf", "subprotf", |
|||
"privf", "subprivf"); |
|||
foreach($classes as $class) { |
|||
echo "Reflecting on class $class: \n"; |
|||
$rc = new ReflectionClass($class); |
|||
echo " --> Check for f(): "; |
|||
var_dump($rc->getMethod("f")); |
|||
echo " --> Check for s(): "; |
|||
var_dump($rc->getMethod("s")); |
|||
echo " --> Check for F(): "; |
|||
var_dump($rc->getMethod("F")); |
|||
echo " --> Check for doesntExist(): "; |
|||
try { |
|||
var_dump($rc->getMethod("doesntExist")); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
Reflecting on class pubf: |
|||
--> Check for f(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
--> Check for s(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
--> Check for F(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
--> Check for doesntExist(): Method doesntExist does not exist |
|||
Reflecting on class subpubf: |
|||
--> Check for f(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
--> Check for s(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
--> Check for F(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
--> Check for doesntExist(): Method doesntExist does not exist |
|||
Reflecting on class protf: |
|||
--> Check for f(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
--> Check for s(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
--> Check for F(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
--> Check for doesntExist(): Method doesntExist does not exist |
|||
Reflecting on class subprotf: |
|||
--> Check for f(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
--> Check for s(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
--> Check for F(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
--> Check for doesntExist(): Method doesntExist does not exist |
|||
Reflecting on class privf: |
|||
--> Check for f(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
--> Check for s(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
--> Check for F(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
--> Check for doesntExist(): Method doesntExist does not exist |
|||
Reflecting on class subprivf: |
|||
--> Check for f(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(8) "subprivf" |
|||
} |
|||
--> Check for s(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(8) "subprivf" |
|||
} |
|||
--> Check for F(): object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(8) "subprivf" |
|||
} |
|||
--> Check for doesntExist(): Method doesntExist does not exist |
|||
@ -0,0 +1,74 @@ |
|||
--TEST-- |
|||
ReflectionClass::getMethod() - error cases |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
function f() {} |
|||
} |
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
echo "Check invalid params:\n"; |
|||
try { |
|||
var_dump($rc->getMethod()); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getMethod("f", "f")); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getMethod(null)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getMethod(1)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getMethod(1.5)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getMethod(true)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getMethod(array(1,2,3))); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getMethod(new C)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Check invalid params: |
|||
|
|||
Warning: ReflectionClass::getMethod() expects exactly 1 parameter, 0 given in %s on line 9 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::getMethod() expects exactly 1 parameter, 2 given in %s on line 14 |
|||
NULL |
|||
Method does not exist |
|||
Method 1 does not exist |
|||
Method 1.5 does not exist |
|||
Method 1 does not exist |
|||
|
|||
Warning: ReflectionClass::getMethod() expects parameter 1 to be string, array given in %s on line 39 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::getMethod() expects parameter 1 to be string, object given in %s on line 44 |
|||
NULL |
|||
@ -0,0 +1,140 @@ |
|||
--TEST-- |
|||
ReflectionClass::getMethods() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class pubf { |
|||
public function f() {} |
|||
static public function s() {} |
|||
} |
|||
class subpubf extends pubf { |
|||
} |
|||
|
|||
class protf { |
|||
protected function f() {} |
|||
static protected function s() {} |
|||
} |
|||
class subprotf extends protf { |
|||
} |
|||
|
|||
class privf { |
|||
private function f() {} |
|||
static private function s() {} |
|||
} |
|||
class subprivf extends privf { |
|||
} |
|||
|
|||
$classes = array("pubf", "subpubf", "protf", "subprotf", |
|||
"privf", "subprivf"); |
|||
foreach($classes as $class) { |
|||
echo "Reflecting on class $class: \n"; |
|||
$rc = new ReflectionClass($class); |
|||
var_dump($rc->getMethods()); |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Reflecting on class pubf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
} |
|||
Reflecting on class subpubf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
} |
|||
Reflecting on class protf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
} |
|||
Reflecting on class subprotf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
} |
|||
Reflecting on class privf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
} |
|||
Reflecting on class subprivf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "f" |
|||
["class"]=> |
|||
string(8) "subprivf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(8) "subprivf" |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
--TEST-- |
|||
ReflectionClass::getMethods() - invalid arguments |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
$rc = new ReflectionClass("ReflectionClass"); |
|||
echo "\nTest invalid arguments:"; |
|||
$rc->getMethods('X'); |
|||
$rc->getMethods('X', true); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Test invalid arguments: |
|||
Warning: ReflectionClass::getMethods() expects parameter 1 to be long, string given in %s on line 4 |
|||
|
|||
Warning: ReflectionClass::getMethods() expects at most 1 parameter, 2 given in %s on line 5 |
|||
@ -0,0 +1,191 @@ |
|||
--TEST-- |
|||
ReflectionClass::getMethods() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
public function pubf1() {} |
|||
public function pubf2() {} |
|||
private function privf1() {} |
|||
private function privf2() {} |
|||
static public function pubsf1() {} |
|||
static public function pubsf2() {} |
|||
static private function privsf1() {} |
|||
static private function privsf2() {} |
|||
} |
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
$StaticFlag = 0x01; |
|||
$pubFlag = 0x100; |
|||
$privFlag = 0x400; |
|||
|
|||
echo "No methods:"; |
|||
var_dump($rc->getMethods(0)); |
|||
|
|||
echo "Public methods:"; |
|||
var_dump($rc->getMethods($pubFlag)); |
|||
|
|||
echo "Private methods:"; |
|||
var_dump($rc->getMethods($privFlag)); |
|||
|
|||
echo "Public or static methods:"; |
|||
var_dump($rc->getMethods($StaticFlag | $pubFlag)); |
|||
|
|||
echo "Private or static methods:"; |
|||
var_dump($rc->getMethods($StaticFlag | $privFlag)); |
|||
|
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
No methods:array(0) { |
|||
} |
|||
Public methods:array(4) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(5) "pubf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(5) "pubf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "pubsf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "pubsf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
Private methods:array(4) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(7) "privsf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(7) "privsf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
Public or static methods:array(6) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(5) "pubf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(5) "pubf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "pubsf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "pubsf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[4]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(7) "privsf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[5]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(7) "privsf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
Private or static methods:array(6) { |
|||
[0]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "pubsf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(6) "pubsf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[4]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(7) "privsf1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[5]=> |
|||
&object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(7) "privsf2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
--TEST-- |
|||
ReflectionClass::getParentClass() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A {} |
|||
class B extends A {} |
|||
|
|||
$rc = new ReflectionClass('B'); |
|||
$parent = $rc->getParentClass(); |
|||
$grandParent = $parent->getParentClass(); |
|||
var_dump($parent, $grandParent); |
|||
|
|||
echo "\nTest bad params:\n"; |
|||
var_dump($rc->getParentClass(null)); |
|||
var_dump($rc->getParentClass('x')); |
|||
var_dump($rc->getParentClass('x', 123)); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
object(ReflectionClass)#%d (1) { |
|||
["name"]=> |
|||
string(1) "A" |
|||
} |
|||
bool(false) |
|||
|
|||
Test bad params: |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 11 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 12 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 13 |
|||
NULL |
|||
@ -0,0 +1,126 @@ |
|||
--TEST-- |
|||
ReflectionClass::getProperties() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class pubf { |
|||
public $a; |
|||
static public $s; |
|||
} |
|||
class subpubf extends pubf { |
|||
} |
|||
|
|||
class protf { |
|||
protected $a; |
|||
static protected $s; |
|||
} |
|||
class subprotf extends protf { |
|||
} |
|||
|
|||
class privf { |
|||
private $a; |
|||
static private $s; |
|||
} |
|||
class subprivf extends privf { |
|||
} |
|||
|
|||
$classes = array("pubf", "subpubf", "protf", "subprotf", |
|||
"privf", "subprivf"); |
|||
foreach($classes as $class) { |
|||
echo "Reflecting on class $class: \n"; |
|||
$rc = new ReflectionClass($class); |
|||
var_dump($rc->getProperties()); |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Reflecting on class pubf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
} |
|||
Reflecting on class subpubf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
} |
|||
Reflecting on class protf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
} |
|||
Reflecting on class subprotf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
} |
|||
Reflecting on class privf: |
|||
array(2) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
} |
|||
Reflecting on class subprivf: |
|||
array(0) { |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
--TEST-- |
|||
ReflectionClass::getProperties() - invalid arguments |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
$rc = new ReflectionClass("ReflectionClass"); |
|||
echo "\nTest invalid arguments:"; |
|||
$rc->getProperties('X'); |
|||
$rc->getProperties('X', true); |
|||
?> |
|||
--EXPECTF-- |
|||
Test invalid arguments: |
|||
Warning: ReflectionClass::getProperties() expects parameter 1 to be long, string given in %s on line 4 |
|||
|
|||
Warning: ReflectionClass::getProperties() expects at most 1 parameter, 2 given in %s on line 5 |
|||
@ -0,0 +1,189 @@ |
|||
--TEST-- |
|||
ReflectionClass::getProperties() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
public $pub1; |
|||
public $pub2; |
|||
private $priv1; |
|||
private $priv2; |
|||
static public $pubs; |
|||
static public $pubs2; |
|||
static private $privs1; |
|||
static private $privs2; |
|||
} |
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
$StaticFlag = 0x01; |
|||
$pubFlag = 0x100; |
|||
$privFlag = 0x400; |
|||
|
|||
echo "No properties:"; |
|||
var_dump($rc->getProperties(0)); |
|||
|
|||
echo "Public properties:"; |
|||
var_dump($rc->getProperties($pubFlag)); |
|||
|
|||
echo "Private properties:"; |
|||
var_dump($rc->getProperties($privFlag)); |
|||
|
|||
echo "Public or static properties:"; |
|||
var_dump($rc->getProperties($StaticFlag | $pubFlag)); |
|||
|
|||
echo "Private or static properties:"; |
|||
var_dump($rc->getProperties($StaticFlag | $privFlag)); |
|||
?> |
|||
--EXPECTF-- |
|||
No properties:array(0) { |
|||
} |
|||
Public properties:array(4) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pub1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pub2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubs" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "pubs2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
Private properties:array(4) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "priv1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "priv2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privs1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privs2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
Public or static properties:array(6) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pub1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pub2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubs" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "pubs2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[4]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privs1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[5]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privs2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
Private or static properties:array(6) { |
|||
[0]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "priv1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[1]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "priv2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[2]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubs" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[3]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "pubs2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[4]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privs1" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
[5]=> |
|||
&object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(6) "privs2" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
} |
|||
@ -0,0 +1,146 @@ |
|||
--TEST-- |
|||
ReflectionClass::getProperty() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class pubf { |
|||
public $a; |
|||
static public $s; |
|||
} |
|||
class subpubf extends pubf { |
|||
} |
|||
|
|||
class protf { |
|||
protected $a; |
|||
static protected $s; |
|||
} |
|||
class subprotf extends protf { |
|||
} |
|||
|
|||
class privf { |
|||
private $a; |
|||
static protected $s; |
|||
} |
|||
class subprivf extends privf { |
|||
} |
|||
|
|||
$classes = array("pubf", "subpubf", "protf", "subprotf", |
|||
"privf", "subprivf"); |
|||
foreach($classes as $class) { |
|||
echo "Reflecting on class $class: \n"; |
|||
$rc = new ReflectionClass($class); |
|||
try { |
|||
echo " --> Check for s: "; |
|||
var_dump($rc->getProperty("s")); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
echo " --> Check for a: "; |
|||
var_dump($rc->getProperty("a")); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
echo " --> Check for A: "; |
|||
var_dump($rc->getProperty("A")); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
echo " --> Check for doesntExist: "; |
|||
var_dump($rc->getProperty("doesntExist")); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
Reflecting on class pubf: |
|||
--> Check for s: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
--> Check for a: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(4) "pubf" |
|||
} |
|||
--> Check for A: Property A does not exist |
|||
--> Check for doesntExist: Property doesntExist does not exist |
|||
Reflecting on class subpubf: |
|||
--> Check for s: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
--> Check for a: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(7) "subpubf" |
|||
} |
|||
--> Check for A: Property A does not exist |
|||
--> Check for doesntExist: Property doesntExist does not exist |
|||
Reflecting on class protf: |
|||
--> Check for s: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
--> Check for a: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(5) "protf" |
|||
} |
|||
--> Check for A: Property A does not exist |
|||
--> Check for doesntExist: Property doesntExist does not exist |
|||
Reflecting on class subprotf: |
|||
--> Check for s: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
--> Check for a: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(8) "subprotf" |
|||
} |
|||
--> Check for A: Property A does not exist |
|||
--> Check for doesntExist: Property doesntExist does not exist |
|||
Reflecting on class privf: |
|||
--> Check for s: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
--> Check for a: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "a" |
|||
["class"]=> |
|||
string(5) "privf" |
|||
} |
|||
--> Check for A: Property A does not exist |
|||
--> Check for doesntExist: Property doesntExist does not exist |
|||
Reflecting on class subprivf: |
|||
--> Check for s: object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(1) "s" |
|||
["class"]=> |
|||
string(8) "subprivf" |
|||
} |
|||
--> Check for a: Property a does not exist |
|||
--> Check for A: Property A does not exist |
|||
--> Check for doesntExist: Property doesntExist does not exist |
|||
@ -0,0 +1,72 @@ |
|||
--TEST-- |
|||
ReflectionClass::getProperty() - error cases |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
public $a; |
|||
} |
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
echo "Check invalid params:\n"; |
|||
try { |
|||
var_dump($rc->getProperty()); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getProperty("a", "a")); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getProperty(null)); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getProperty(1)); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getProperty(1.5)); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getProperty(true)); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getProperty(array(1,2,3))); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getProperty(new C)); |
|||
} catch (exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
Check invalid params: |
|||
|
|||
Warning: ReflectionClass::getProperty() expects exactly 1 parameter, 0 given in %s on line 9 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::getProperty() expects exactly 1 parameter, 2 given in %s on line 14 |
|||
NULL |
|||
Property does not exist |
|||
Property 1 does not exist |
|||
Property 1.5 does not exist |
|||
Property 1 does not exist |
|||
|
|||
Warning: ReflectionClass::getProperty() expects parameter 1 to be string, array given in %s on line 39 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::getProperty() expects parameter 1 to be string, object given in %s on line 44 |
|||
NULL |
|||
@ -0,0 +1,251 @@ |
|||
--TEST-- |
|||
ReflectionClass::getProperty() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A { |
|||
static public $pubC = "pubC in A"; |
|||
static protected $protC = "protC in A"; |
|||
static private $privC = "privC in A"; |
|||
|
|||
static public $pubA = "pubA in A"; |
|||
static protected $protA = "protA in A"; |
|||
static private $privA = "privA in A"; |
|||
} |
|||
|
|||
class B extends A { |
|||
static public $pubC = "pubC in B"; |
|||
static protected $protC = "protC in B"; |
|||
static private $privC = "privC in B"; |
|||
|
|||
static public $pubB = "pubB in B"; |
|||
static protected $protB = "protB in B"; |
|||
static private $privB = "privB in B"; |
|||
} |
|||
|
|||
class C extends B { |
|||
static public $pubC = "pubC in C"; |
|||
static protected $protC = "protC in C"; |
|||
static private $privC = "privC in C"; |
|||
} |
|||
|
|||
class X { |
|||
static public $pubC = "pubC in X"; |
|||
static protected $protC = "protC in X"; |
|||
static private $privC = "privC in X"; |
|||
} |
|||
|
|||
$myC = new C; |
|||
$rc = new ReflectionClass("C"); |
|||
|
|||
function showInfo($name) { |
|||
global $rc, $myC; |
|||
echo "--- (Reflecting on $name) ---\n"; |
|||
try { |
|||
$rp = $rc->getProperty($name); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
return; |
|||
} |
|||
try { |
|||
var_dump($rp); |
|||
var_dump($rp->getValue($myC)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
return; |
|||
} |
|||
} |
|||
|
|||
|
|||
showInfo("pubA"); |
|||
showInfo("protA"); |
|||
showInfo("privA"); |
|||
|
|||
showInfo("pubB"); |
|||
showInfo("protB"); |
|||
showInfo("privB"); |
|||
|
|||
showInfo("pubC"); |
|||
showInfo("protC"); |
|||
showInfo("privC"); |
|||
showInfo("doesntExist"); |
|||
|
|||
showInfo("A::pubC"); |
|||
showInfo("A::protC"); |
|||
showInfo("A::privC"); |
|||
|
|||
showInfo("B::pubC"); |
|||
showInfo("B::protC"); |
|||
showInfo("B::privC"); |
|||
|
|||
showInfo("c::pubC"); |
|||
showInfo("c::PUBC"); |
|||
showInfo("C::pubC"); |
|||
showInfo("C::protC"); |
|||
showInfo("C::privC"); |
|||
|
|||
showInfo("X::pubC"); |
|||
showInfo("X::protC"); |
|||
showInfo("X::privC"); |
|||
showInfo("X::doesntExist"); |
|||
|
|||
showInfo("doesntexist::doesntExist"); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
--- (Reflecting on pubA) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubA" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubA in A" |
|||
--- (Reflecting on protA) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protA" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protA |
|||
--- (Reflecting on privA) --- |
|||
Property privA does not exist |
|||
--- (Reflecting on pubB) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubB" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubB in B" |
|||
--- (Reflecting on protB) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protB" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protB |
|||
--- (Reflecting on privB) --- |
|||
Property privB does not exist |
|||
--- (Reflecting on pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protC |
|||
--- (Reflecting on privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::privC |
|||
--- (Reflecting on doesntExist) --- |
|||
Property doesntExist does not exist |
|||
--- (Reflecting on A::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "A" |
|||
} |
|||
string(9) "pubC in A" |
|||
--- (Reflecting on A::protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "A" |
|||
} |
|||
Cannot access non-public member A::protC |
|||
--- (Reflecting on A::privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "A" |
|||
} |
|||
Cannot access non-public member A::privC |
|||
--- (Reflecting on B::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "B" |
|||
} |
|||
string(9) "pubC in B" |
|||
--- (Reflecting on B::protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "B" |
|||
} |
|||
Cannot access non-public member B::protC |
|||
--- (Reflecting on B::privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "B" |
|||
} |
|||
Cannot access non-public member B::privC |
|||
--- (Reflecting on c::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on c::PUBC) --- |
|||
Property PUBC does not exist |
|||
--- (Reflecting on C::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on C::protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protC |
|||
--- (Reflecting on C::privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::privC |
|||
--- (Reflecting on X::pubC) --- |
|||
Fully qualified property name X::pubC does not specify a base class of C |
|||
--- (Reflecting on X::protC) --- |
|||
Fully qualified property name X::protC does not specify a base class of C |
|||
--- (Reflecting on X::privC) --- |
|||
Fully qualified property name X::privC does not specify a base class of C |
|||
--- (Reflecting on X::doesntExist) --- |
|||
Fully qualified property name X::doesntExist does not specify a base class of C |
|||
--- (Reflecting on doesntexist::doesntExist) --- |
|||
Class doesntexist does not exist |
|||
@ -0,0 +1,251 @@ |
|||
--TEST-- |
|||
ReflectionClass::getProperty() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A { |
|||
public $pubC = "pubC in A"; |
|||
protected $protC = "protC in A"; |
|||
private $privC = "privC in A"; |
|||
|
|||
public $pubA = "pubA in A"; |
|||
protected $protA = "protA in A"; |
|||
private $privA = "privA in A"; |
|||
} |
|||
|
|||
class B extends A { |
|||
public $pubC = "pubC in B"; |
|||
protected $protC = "protC in B"; |
|||
private $privC = "privC in B"; |
|||
|
|||
public $pubB = "pubB in B"; |
|||
protected $protB = "protB in B"; |
|||
private $privB = "privB in B"; |
|||
} |
|||
|
|||
class C extends B { |
|||
public $pubC = "pubC in C"; |
|||
protected $protC = "protC in C"; |
|||
private $privC = "privC in C"; |
|||
} |
|||
|
|||
class X { |
|||
public $pubC = "pubC in X"; |
|||
protected $protC = "protC in X"; |
|||
private $privC = "privC in X"; |
|||
} |
|||
|
|||
$myC = new C; |
|||
$rc = new ReflectionClass("C"); |
|||
|
|||
function showInfo($name) { |
|||
global $rc, $myC; |
|||
echo "--- (Reflecting on $name) ---\n"; |
|||
try { |
|||
$rp = $rc->getProperty($name); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
return; |
|||
} |
|||
try { |
|||
var_dump($rp); |
|||
var_dump($rp->getValue($myC)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
return; |
|||
} |
|||
} |
|||
|
|||
|
|||
showInfo("pubA"); |
|||
showInfo("protA"); |
|||
showInfo("privA"); |
|||
|
|||
showInfo("pubB"); |
|||
showInfo("protB"); |
|||
showInfo("privB"); |
|||
|
|||
showInfo("pubC"); |
|||
showInfo("protC"); |
|||
showInfo("privC"); |
|||
showInfo("doesntExist"); |
|||
|
|||
showInfo("A::pubC"); |
|||
showInfo("A::protC"); |
|||
showInfo("A::privC"); |
|||
|
|||
showInfo("B::pubC"); |
|||
showInfo("B::protC"); |
|||
showInfo("B::privC"); |
|||
|
|||
showInfo("c::pubC"); |
|||
showInfo("c::PUBC"); |
|||
showInfo("C::pubC"); |
|||
showInfo("C::protC"); |
|||
showInfo("C::privC"); |
|||
|
|||
showInfo("X::pubC"); |
|||
showInfo("X::protC"); |
|||
showInfo("X::privC"); |
|||
showInfo("X::doesntExist"); |
|||
|
|||
showInfo("doesntexist::doesntExist"); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
--- (Reflecting on pubA) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubA" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubA in A" |
|||
--- (Reflecting on protA) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protA" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protA |
|||
--- (Reflecting on privA) --- |
|||
Property privA does not exist |
|||
--- (Reflecting on pubB) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubB" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubB in B" |
|||
--- (Reflecting on protB) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protB" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protB |
|||
--- (Reflecting on privB) --- |
|||
Property privB does not exist |
|||
--- (Reflecting on pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protC |
|||
--- (Reflecting on privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::privC |
|||
--- (Reflecting on doesntExist) --- |
|||
Property doesntExist does not exist |
|||
--- (Reflecting on A::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "A" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on A::protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "A" |
|||
} |
|||
Cannot access non-public member A::protC |
|||
--- (Reflecting on A::privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "A" |
|||
} |
|||
Cannot access non-public member A::privC |
|||
--- (Reflecting on B::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "B" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on B::protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "B" |
|||
} |
|||
Cannot access non-public member B::protC |
|||
--- (Reflecting on B::privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "B" |
|||
} |
|||
Cannot access non-public member B::privC |
|||
--- (Reflecting on c::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on c::PUBC) --- |
|||
Property PUBC does not exist |
|||
--- (Reflecting on C::pubC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(4) "pubC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
string(9) "pubC in C" |
|||
--- (Reflecting on C::protC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "protC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::protC |
|||
--- (Reflecting on C::privC) --- |
|||
object(ReflectionProperty)#%d (2) { |
|||
["name"]=> |
|||
string(5) "privC" |
|||
["class"]=> |
|||
string(1) "C" |
|||
} |
|||
Cannot access non-public member C::privC |
|||
--- (Reflecting on X::pubC) --- |
|||
Fully qualified property name X::pubC does not specify a base class of C |
|||
--- (Reflecting on X::protC) --- |
|||
Fully qualified property name X::protC does not specify a base class of C |
|||
--- (Reflecting on X::privC) --- |
|||
Fully qualified property name X::privC does not specify a base class of C |
|||
--- (Reflecting on X::doesntExist) --- |
|||
Fully qualified property name X::doesntExist does not specify a base class of C |
|||
--- (Reflecting on doesntexist::doesntExist) --- |
|||
Class doesntexist does not exist |
|||
@ -0,0 +1,67 @@ |
|||
--TEST-- |
|||
ReflectionClass::getStaticPropertyValue() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A { |
|||
static private $privateOverridden = "original private"; |
|||
static protected $protectedOverridden = "original protected"; |
|||
static public $publicOverridden = "original public"; |
|||
} |
|||
|
|||
class B extends A { |
|||
static private $privateOverridden = "changed private"; |
|||
static protected $protectedOverridden = "changed protected"; |
|||
static public $publicOverridden = "changed public"; |
|||
} |
|||
|
|||
echo "Retrieving static values from A:\n"; |
|||
$rcA = new ReflectionClass('A'); |
|||
var_dump($rcA->getStaticPropertyValue("privateOverridden", "default value")); |
|||
var_dump($rcA->getStaticPropertyValue("\0A\0privateOverridden")); |
|||
var_dump($rcA->getStaticPropertyValue("protectedOverridden", "default value")); |
|||
var_dump($rcA->getStaticPropertyValue("\0*\0protectedOverridden")); |
|||
var_dump($rcA->getStaticPropertyValue("publicOverridden")); |
|||
|
|||
echo "\nRetrieving static values from B:\n"; |
|||
$rcB = new ReflectionClass('B'); |
|||
var_dump($rcB->getStaticPropertyValue("\0A\0privateOverridden")); |
|||
var_dump($rcB->getStaticPropertyValue("\0B\0privateOverridden")); |
|||
var_dump($rcB->getStaticPropertyValue("\0*\0protectedOverridden")); |
|||
var_dump($rcB->getStaticPropertyValue("publicOverridden")); |
|||
|
|||
echo "\nRetrieving non-existent values from A with no default value:\n"; |
|||
try { |
|||
var_dump($rcA->getStaticPropertyValue("protectedOverridden")); |
|||
echo "you should not see this"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
try { |
|||
var_dump($rcA->getStaticPropertyValue("privateOverridden")); |
|||
echo "you should not see this"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Retrieving static values from A: |
|||
string(13) "default value" |
|||
string(16) "original private" |
|||
string(13) "default value" |
|||
string(18) "original protected" |
|||
string(15) "original public" |
|||
|
|||
Retrieving static values from B: |
|||
string(16) "original private" |
|||
string(15) "changed private" |
|||
string(17) "changed protected" |
|||
string(14) "changed public" |
|||
|
|||
Retrieving non-existent values from A with no default value: |
|||
Class A does not have a property named protectedOverridden |
|||
Class A does not have a property named privateOverridden |
|||
@ -0,0 +1,52 @@ |
|||
--TEST-- |
|||
ReflectionClass::getStaticPropertyValue() - bad params |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
public static $x; |
|||
} |
|||
|
|||
$rc = new ReflectionClass('C'); |
|||
try { |
|||
var_dump($rc->getStaticPropertyValue("x", "default value", 'blah')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getStaticPropertyValue()); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getStaticPropertyValue(null)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getStaticPropertyValue(1.5, 'def')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->getStaticPropertyValue(array(1,2,3))); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: ReflectionClass::getStaticPropertyValue() expects at most 2 parameters, 3 given in %s on line 8 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::getStaticPropertyValue() expects at least 1 parameter, 0 given in %s on line 13 |
|||
NULL |
|||
Class C does not have a property named |
|||
string(3) "def" |
|||
|
|||
Warning: ReflectionClass::getStaticPropertyValue() expects parameter 1 to be string, array given in %s on line 28 |
|||
NULL |
|||
@ -0,0 +1,36 @@ |
|||
--TEST-- |
|||
ReflectionClass::hasConstant() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
const myConst = 1; |
|||
} |
|||
|
|||
class D extends C { |
|||
} |
|||
|
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
echo "Check existing constant: "; |
|||
var_dump($rc->hasConstant("myConst")); |
|||
echo "Check existing constant, different case: "; |
|||
var_dump($rc->hasConstant("MyCoNsT")); |
|||
echo "Check absent constant: "; |
|||
var_dump($rc->hasConstant("doesntExist")); |
|||
|
|||
|
|||
$rd = new ReflectionClass("D"); |
|||
echo "Check inherited constant: "; |
|||
var_dump($rd->hasConstant("myConst")); |
|||
echo "Check absent constant: "; |
|||
var_dump($rd->hasConstant("doesntExist")); |
|||
?> |
|||
--EXPECTF-- |
|||
Check existing constant: bool(true) |
|||
Check existing constant, different case: bool(false) |
|||
Check absent constant: bool(false) |
|||
Check inherited constant: bool(true) |
|||
Check absent constant: bool(false) |
|||
@ -0,0 +1,40 @@ |
|||
--TEST-- |
|||
ReflectionClass::hasConstant() - error cases |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
const myConst = 1; |
|||
} |
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
echo "Check invalid params:\n"; |
|||
var_dump($rc->hasConstant()); |
|||
var_dump($rc->hasConstant("myConst", "myConst")); |
|||
var_dump($rc->hasConstant(null)); |
|||
var_dump($rc->hasConstant(1)); |
|||
var_dump($rc->hasConstant(1.5)); |
|||
var_dump($rc->hasConstant(true)); |
|||
var_dump($rc->hasConstant(array(1,2,3))); |
|||
var_dump($rc->hasConstant(new C)); |
|||
?> |
|||
--EXPECTF-- |
|||
Check invalid params: |
|||
|
|||
Warning: ReflectionClass::hasConstant() expects exactly 1 parameter, 0 given in %s on line 8 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::hasConstant() expects exactly 1 parameter, 2 given in %s on line 9 |
|||
NULL |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
|
|||
Warning: ReflectionClass::hasConstant() expects parameter 1 to be string, array given in %s on line 14 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::hasConstant() expects parameter 1 to be string, object given in %s on line 15 |
|||
NULL |
|||
@ -0,0 +1,75 @@ |
|||
--TEST-- |
|||
ReflectionClass::hasMethod() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class pubf { |
|||
public function f() {} |
|||
static public function s() {} |
|||
} |
|||
class subpubf extends pubf { |
|||
} |
|||
|
|||
class protf { |
|||
protected function f() {} |
|||
static protected function s() {} |
|||
} |
|||
class subprotf extends protf { |
|||
} |
|||
|
|||
class privf { |
|||
private function f() {} |
|||
static private function s() {} |
|||
} |
|||
class subprivf extends privf { |
|||
} |
|||
|
|||
$classes = array("pubf", "subpubf", "protf", "subprotf", |
|||
"privf", "subprivf"); |
|||
foreach($classes as $class) { |
|||
echo "Reflecting on class $class: \n"; |
|||
$rc = new ReflectionClass($class); |
|||
echo " --> Check for f(): "; |
|||
var_dump($rc->hasMethod("f")); |
|||
echo " --> Check for s(): "; |
|||
var_dump($rc->hasMethod("s")); |
|||
echo " --> Check for F(): "; |
|||
var_dump($rc->hasMethod("F")); |
|||
echo " --> Check for doesntExist(): "; |
|||
var_dump($rc->hasMethod("doesntExist")); |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
Reflecting on class pubf: |
|||
--> Check for f(): bool(true) |
|||
--> Check for s(): bool(true) |
|||
--> Check for F(): bool(true) |
|||
--> Check for doesntExist(): bool(false) |
|||
Reflecting on class subpubf: |
|||
--> Check for f(): bool(true) |
|||
--> Check for s(): bool(true) |
|||
--> Check for F(): bool(true) |
|||
--> Check for doesntExist(): bool(false) |
|||
Reflecting on class protf: |
|||
--> Check for f(): bool(true) |
|||
--> Check for s(): bool(true) |
|||
--> Check for F(): bool(true) |
|||
--> Check for doesntExist(): bool(false) |
|||
Reflecting on class subprotf: |
|||
--> Check for f(): bool(true) |
|||
--> Check for s(): bool(true) |
|||
--> Check for F(): bool(true) |
|||
--> Check for doesntExist(): bool(false) |
|||
Reflecting on class privf: |
|||
--> Check for f(): bool(true) |
|||
--> Check for s(): bool(true) |
|||
--> Check for F(): bool(true) |
|||
--> Check for doesntExist(): bool(false) |
|||
Reflecting on class subprivf: |
|||
--> Check for f(): bool(true) |
|||
--> Check for s(): bool(true) |
|||
--> Check for F(): bool(true) |
|||
--> Check for doesntExist(): bool(false) |
|||
|
|||
@ -0,0 +1,40 @@ |
|||
--TEST-- |
|||
ReflectionClass::hasMethod() - error cases |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
function f() {} |
|||
} |
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
echo "Check invalid params:\n"; |
|||
var_dump($rc->hasMethod()); |
|||
var_dump($rc->hasMethod("f", "f")); |
|||
var_dump($rc->hasMethod(null)); |
|||
var_dump($rc->hasMethod(1)); |
|||
var_dump($rc->hasMethod(1.5)); |
|||
var_dump($rc->hasMethod(true)); |
|||
var_dump($rc->hasMethod(array(1,2,3))); |
|||
var_dump($rc->hasMethod(new C)); |
|||
?> |
|||
--EXPECTF-- |
|||
Check invalid params: |
|||
|
|||
Warning: ReflectionClass::hasMethod() expects exactly 1 parameter, 0 given in %s on line 8 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::hasMethod() expects exactly 1 parameter, 2 given in %s on line 9 |
|||
NULL |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
|
|||
Warning: ReflectionClass::hasMethod() expects parameter 1 to be string, array given in %s on line 14 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::hasMethod() expects parameter 1 to be string, object given in %s on line 15 |
|||
NULL |
|||
@ -0,0 +1,75 @@ |
|||
--TEST-- |
|||
ReflectionClass::hasProperty() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class pubf { |
|||
public $a; |
|||
static public $s; |
|||
} |
|||
class subpubf extends pubf { |
|||
} |
|||
|
|||
class protf { |
|||
protected $a; |
|||
static protected $s; |
|||
} |
|||
class subprotf extends protf { |
|||
} |
|||
|
|||
class privf { |
|||
private $a; |
|||
static protected $s; |
|||
} |
|||
class subprivf extends privf { |
|||
} |
|||
|
|||
$classes = array("pubf", "subpubf", "protf", "subprotf", |
|||
"privf", "subprivf"); |
|||
foreach($classes as $class) { |
|||
echo "Reflecting on class $class: \n"; |
|||
$rc = new ReflectionClass($class); |
|||
echo " --> Check for s: "; |
|||
var_dump($rc->hasProperty("s")); |
|||
echo " --> Check for a: "; |
|||
var_dump($rc->hasProperty("a")); |
|||
echo " --> Check for A: "; |
|||
var_dump($rc->hasProperty("A")); |
|||
echo " --> Check for doesntExist: "; |
|||
var_dump($rc->hasProperty("doesntExist")); |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
Reflecting on class pubf: |
|||
--> Check for s: bool(true) |
|||
--> Check for a: bool(true) |
|||
--> Check for A: bool(false) |
|||
--> Check for doesntExist: bool(false) |
|||
Reflecting on class subpubf: |
|||
--> Check for s: bool(true) |
|||
--> Check for a: bool(true) |
|||
--> Check for A: bool(false) |
|||
--> Check for doesntExist: bool(false) |
|||
Reflecting on class protf: |
|||
--> Check for s: bool(true) |
|||
--> Check for a: bool(true) |
|||
--> Check for A: bool(false) |
|||
--> Check for doesntExist: bool(false) |
|||
Reflecting on class subprotf: |
|||
--> Check for s: bool(true) |
|||
--> Check for a: bool(true) |
|||
--> Check for A: bool(false) |
|||
--> Check for doesntExist: bool(false) |
|||
Reflecting on class privf: |
|||
--> Check for s: bool(true) |
|||
--> Check for a: bool(true) |
|||
--> Check for A: bool(false) |
|||
--> Check for doesntExist: bool(false) |
|||
Reflecting on class subprivf: |
|||
--> Check for s: bool(true) |
|||
--> Check for a: bool(true) |
|||
--> Check for A: bool(false) |
|||
--> Check for doesntExist: bool(false) |
|||
|
|||
@ -0,0 +1,40 @@ |
|||
--TEST-- |
|||
ReflectionClass::hasProperty() - error cases |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
public $a; |
|||
} |
|||
|
|||
$rc = new ReflectionClass("C"); |
|||
echo "Check invalid params:\n"; |
|||
var_dump($rc->hasProperty()); |
|||
var_dump($rc->hasProperty("a", "a")); |
|||
var_dump($rc->hasProperty(null)); |
|||
var_dump($rc->hasProperty(1)); |
|||
var_dump($rc->hasProperty(1.5)); |
|||
var_dump($rc->hasProperty(true)); |
|||
var_dump($rc->hasProperty(array(1,2,3))); |
|||
var_dump($rc->hasProperty(new C)); |
|||
?> |
|||
--EXPECTF-- |
|||
Check invalid params: |
|||
|
|||
Warning: ReflectionClass::hasProperty() expects exactly 1 parameter, 0 given in %s on line 8 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::hasProperty() expects exactly 1 parameter, 2 given in %s on line 9 |
|||
NULL |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
|
|||
Warning: ReflectionClass::hasProperty() expects parameter 1 to be string, array given in %s on line 14 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::hasProperty() expects parameter 1 to be string, object given in %s on line 15 |
|||
NULL |
|||
@ -0,0 +1,155 @@ |
|||
--TEST-- |
|||
ReflectionClass::implementsInterface() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
interface I1 {} |
|||
class A implements I1 {} |
|||
class B extends A {} |
|||
|
|||
interface I2 extends I1 {} |
|||
class C implements I2 {} |
|||
|
|||
$classNames = array('A', 'B', 'C', 'I1', 'I2'); |
|||
|
|||
foreach ($classNames as $className) { |
|||
$rcs[$className] = new ReflectionClass($className); |
|||
} |
|||
|
|||
foreach ($rcs as $childName => $child) { |
|||
foreach ($rcs as $parentName => $parent) { |
|||
echo "Does " . $childName . " implement " . $parentName . "? \n"; |
|||
echo " - Using object argument: "; |
|||
try { |
|||
var_dump($child->implementsInterface($parent)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
echo " - Using string argument: "; |
|||
try { |
|||
var_dump($child->implementsInterface($parentName)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
echo "\n\nTest bad arguments:\n"; |
|||
try { |
|||
var_dump($rcs['A']->implementsInterface()); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rcs['A']->implementsInterface('C', 'C')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rcs['A']->implementsInterface(null)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rcs['A']->implementsInterface('ThisClassDoesNotExist')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rcs['A']->implementsInterface(2)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
Does A implement A? |
|||
- Using object argument: Interface A is a Class |
|||
- Using string argument: Interface A is a Class |
|||
Does A implement B? |
|||
- Using object argument: Interface B is a Class |
|||
- Using string argument: Interface B is a Class |
|||
Does A implement C? |
|||
- Using object argument: Interface C is a Class |
|||
- Using string argument: Interface C is a Class |
|||
Does A implement I1? |
|||
- Using object argument: bool(true) |
|||
- Using string argument: bool(true) |
|||
Does A implement I2? |
|||
- Using object argument: bool(false) |
|||
- Using string argument: bool(false) |
|||
Does B implement A? |
|||
- Using object argument: Interface A is a Class |
|||
- Using string argument: Interface A is a Class |
|||
Does B implement B? |
|||
- Using object argument: Interface B is a Class |
|||
- Using string argument: Interface B is a Class |
|||
Does B implement C? |
|||
- Using object argument: Interface C is a Class |
|||
- Using string argument: Interface C is a Class |
|||
Does B implement I1? |
|||
- Using object argument: bool(true) |
|||
- Using string argument: bool(true) |
|||
Does B implement I2? |
|||
- Using object argument: bool(false) |
|||
- Using string argument: bool(false) |
|||
Does C implement A? |
|||
- Using object argument: Interface A is a Class |
|||
- Using string argument: Interface A is a Class |
|||
Does C implement B? |
|||
- Using object argument: Interface B is a Class |
|||
- Using string argument: Interface B is a Class |
|||
Does C implement C? |
|||
- Using object argument: Interface C is a Class |
|||
- Using string argument: Interface C is a Class |
|||
Does C implement I1? |
|||
- Using object argument: bool(true) |
|||
- Using string argument: bool(true) |
|||
Does C implement I2? |
|||
- Using object argument: bool(true) |
|||
- Using string argument: bool(true) |
|||
Does I1 implement A? |
|||
- Using object argument: Interface A is a Class |
|||
- Using string argument: Interface A is a Class |
|||
Does I1 implement B? |
|||
- Using object argument: Interface B is a Class |
|||
- Using string argument: Interface B is a Class |
|||
Does I1 implement C? |
|||
- Using object argument: Interface C is a Class |
|||
- Using string argument: Interface C is a Class |
|||
Does I1 implement I1? |
|||
- Using object argument: bool(true) |
|||
- Using string argument: bool(true) |
|||
Does I1 implement I2? |
|||
- Using object argument: bool(false) |
|||
- Using string argument: bool(false) |
|||
Does I2 implement A? |
|||
- Using object argument: Interface A is a Class |
|||
- Using string argument: Interface A is a Class |
|||
Does I2 implement B? |
|||
- Using object argument: Interface B is a Class |
|||
- Using string argument: Interface B is a Class |
|||
Does I2 implement C? |
|||
- Using object argument: Interface C is a Class |
|||
- Using string argument: Interface C is a Class |
|||
Does I2 implement I1? |
|||
- Using object argument: bool(true) |
|||
- Using string argument: bool(true) |
|||
Does I2 implement I2? |
|||
- Using object argument: bool(true) |
|||
- Using string argument: bool(true) |
|||
|
|||
|
|||
Test bad arguments: |
|||
|
|||
Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 0 given in %s on line 37 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 2 given in %s on line 42 |
|||
NULL |
|||
Parameter one must either be a string or a ReflectionClass object |
|||
Interface ThisClassDoesNotExist does not exist |
|||
Parameter one must either be a string or a ReflectionClass object |
|||
@ -0,0 +1,75 @@ |
|||
--TEST-- |
|||
ReflectionClass::isIterateable() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
Interface ExtendsIterator extends Iterator { |
|||
} |
|||
Interface ExtendsIteratorAggregate extends IteratorAggregate { |
|||
} |
|||
Class IteratorImpl implements Iterator { |
|||
public function next() {} |
|||
public function key() {} |
|||
public function rewind() {} |
|||
public function current() {} |
|||
public function valid() {} |
|||
} |
|||
Class IterarorAggregateImpl implements IteratorAggregate { |
|||
public function getIterator() {} |
|||
} |
|||
Class ExtendsIteratorImpl extends IteratorImpl { |
|||
} |
|||
Class ExtendsIteratorAggregateImpl extends IterarorAggregateImpl { |
|||
} |
|||
Class A { |
|||
} |
|||
|
|||
$classes = array('Traversable', 'Iterator', 'IteratorAggregate', 'ExtendsIterator', 'ExtendsIteratorAggregate', |
|||
'IteratorImpl', 'IterarorAggregateImpl', 'ExtendsIteratorImpl', 'ExtendsIteratorAggregateImpl', 'A'); |
|||
|
|||
foreach($classes as $class) { |
|||
$rc = new ReflectionClass($class); |
|||
echo "Is $class iterable? "; |
|||
var_dump($rc->isIterateable()); |
|||
} |
|||
|
|||
echo "\nTest invalid params:\n"; |
|||
$rc = new ReflectionClass('IteratorImpl'); |
|||
var_dump($rc->isIterateable(null)); |
|||
var_dump($rc->isIterateable(null, null)); |
|||
var_dump($rc->isIterateable(1)); |
|||
var_dump($rc->isIterateable(1.5)); |
|||
var_dump($rc->isIterateable(true)); |
|||
var_dump($rc->isIterateable('X')); |
|||
var_dump($rc->isIterateable(null)); |
|||
|
|||
echo "\nTest static invocation:\n"; |
|||
ReflectionClass::isIterateable(); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Is Traversable iterable? bool(false) |
|||
Is Iterator iterable? bool(false) |
|||
Is IteratorAggregate iterable? bool(false) |
|||
Is ExtendsIterator iterable? bool(false) |
|||
Is ExtendsIteratorAggregate iterable? bool(false) |
|||
Is IteratorImpl iterable? bool(true) |
|||
Is IterarorAggregateImpl iterable? bool(true) |
|||
Is ExtendsIteratorImpl iterable? bool(true) |
|||
Is ExtendsIteratorAggregateImpl iterable? bool(true) |
|||
Is A iterable? bool(false) |
|||
|
|||
Test invalid params: |
|||
bool(true) |
|||
bool(true) |
|||
bool(true) |
|||
bool(true) |
|||
bool(true) |
|||
bool(true) |
|||
bool(true) |
|||
|
|||
Test static invocation: |
|||
|
|||
Fatal error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s on line 43 |
|||
@ -0,0 +1,49 @@ |
|||
--TEST-- |
|||
ReflectionObject::isSubclassOf() - bad arguments |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A {} |
|||
$rc = new ReflectionClass('A'); |
|||
|
|||
echo "\n\nTest bad arguments:\n"; |
|||
try { |
|||
var_dump($rc->isSubclassOf()); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->isSubclassOf('C', 'C')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->isSubclassOf(null)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->isSubclassOf('ThisClassDoesNotExist')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->isSubclassOf(2)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Test bad arguments: |
|||
|
|||
Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 7 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 12 |
|||
NULL |
|||
Parameter one must either be a string or a ReflectionClass object |
|||
Class ThisClassDoesNotExist does not exist |
|||
Parameter one must either be a string or a ReflectionClass object |
|||
@ -0,0 +1,44 @@ |
|||
--TEST-- |
|||
Modifiers |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
abstract class A {} |
|||
class B extends A {} |
|||
class C {} |
|||
final class D {} |
|||
interface I {} |
|||
|
|||
$classes = array("A", "B", "C", "D", "I"); |
|||
|
|||
foreach ($classes as $class) { |
|||
$rc = new ReflectionClass($class); |
|||
var_dump($rc->isFinal()); |
|||
var_dump($rc->isInterface()); |
|||
var_dump($rc->isAbstract()); |
|||
var_dump($rc->getModifiers()); |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
bool(false) |
|||
bool(false) |
|||
bool(true) |
|||
int(32) |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
int(0) |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
int(0) |
|||
bool(true) |
|||
bool(false) |
|||
bool(false) |
|||
int(64) |
|||
bool(false) |
|||
bool(true) |
|||
bool(false) |
|||
int(128) |
|||
@ -0,0 +1,28 @@ |
|||
--TEST-- |
|||
Modifiers - wrong param count |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C {} |
|||
$rc = new ReflectionClass("C"); |
|||
var_dump($rc->isFinal('X')); |
|||
var_dump($rc->isInterface(null)); |
|||
var_dump($rc->isAbstract(true)); |
|||
var_dump($rc->getModifiers(array(1,2,3))); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::isFinal() in %s on line 4 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::isInterface() in %s on line 5 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::isAbstract() in %s on line 6 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionClass::getModifiers() in %s on line 7 |
|||
NULL |
|||
@ -0,0 +1,98 @@ |
|||
--TEST-- |
|||
ReflectionClass::newInstanceArgs |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A { |
|||
public function A() { |
|||
echo "In constructor of class A\n"; |
|||
} |
|||
} |
|||
|
|||
class B { |
|||
public function __construct($a, $b) { |
|||
echo "In constructor of class B with args $a, $b\n"; |
|||
} |
|||
} |
|||
|
|||
class C { |
|||
protected function __construct() { |
|||
echo "In constructor of class C\n"; |
|||
} |
|||
} |
|||
|
|||
class D { |
|||
private function __construct() { |
|||
echo "In constructor of class D\n"; |
|||
} |
|||
} |
|||
class E { |
|||
} |
|||
|
|||
|
|||
$rcA = new ReflectionClass('A'); |
|||
$rcB = new ReflectionClass('B'); |
|||
$rcC = new ReflectionClass('C'); |
|||
$rcD = new ReflectionClass('D'); |
|||
$rcE = new ReflectionClass('E'); |
|||
|
|||
$a1 = $rcA->newInstanceArgs(); |
|||
$a2 = $rcA->newInstanceArgs(array('x')); |
|||
var_dump($a1, $a2); |
|||
|
|||
$b1 = $rcB->newInstanceArgs(); |
|||
$b2 = $rcB->newInstanceArgs(array('x', 123)); |
|||
var_dump($b1, $b2); |
|||
|
|||
try { |
|||
$rcC->newInstanceArgs(); |
|||
echo "you should not see this\n"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
try { |
|||
$rcD->newInstanceArgs(); |
|||
echo "you should not see this\n"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
$e1 = $rcE->newInstanceArgs(); |
|||
var_dump($e1); |
|||
|
|||
try { |
|||
$e2 = $rcE->newInstanceArgs(array('x')); |
|||
echo "you should not see this\n"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
In constructor of class A |
|||
In constructor of class A |
|||
object(A)#%d (0) { |
|||
} |
|||
object(A)#%d (0) { |
|||
} |
|||
|
|||
Warning: Missing argument 1 for B::__construct() in %s on line 9 |
|||
|
|||
Warning: Missing argument 2 for B::__construct() in %s on line 9 |
|||
|
|||
Notice: Undefined variable: a in %s on line 10 |
|||
|
|||
Notice: Undefined variable: b in %s on line 10 |
|||
In constructor of class B with args , |
|||
In constructor of class B with args x, 123 |
|||
object(B)#%d (0) { |
|||
} |
|||
object(B)#%d (0) { |
|||
} |
|||
Access to non-public constructor of class C |
|||
Access to non-public constructor of class D |
|||
object(E)#%d (0) { |
|||
} |
|||
Class E does not have a constructor, so you cannot pass any constructor arguments |
|||
@ -0,0 +1,20 @@ |
|||
--TEST-- |
|||
ReflectionClass::newInstanceArgs() - wrong arg type |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A { |
|||
public function __construct($a, $b) { |
|||
echo "In constructor of class B with arg $a\n"; |
|||
} |
|||
} |
|||
$rc = new ReflectionClass('A'); |
|||
$a = $rc->newInstanceArgs('x'); |
|||
var_dump($a); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Catchable fatal error: Argument 1 passed to ReflectionClass::newInstanceArgs() must be an array, string given in %s on line 8 |
|||
@ -0,0 +1,98 @@ |
|||
--TEST-- |
|||
ReflectionClass::newInstance() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A { |
|||
public function A() { |
|||
echo "In constructor of class A\n"; |
|||
} |
|||
} |
|||
|
|||
class B { |
|||
public function __construct($a, $b) { |
|||
echo "In constructor of class B with args $a, $b\n"; |
|||
} |
|||
} |
|||
|
|||
class C { |
|||
protected function __construct() { |
|||
echo "In constructor of class C\n"; |
|||
} |
|||
} |
|||
|
|||
class D { |
|||
private function __construct() { |
|||
echo "In constructor of class D\n"; |
|||
} |
|||
} |
|||
class E { |
|||
} |
|||
|
|||
|
|||
$rcA = new ReflectionClass('A'); |
|||
$rcB = new ReflectionClass('B'); |
|||
$rcC = new ReflectionClass('C'); |
|||
$rcD = new ReflectionClass('D'); |
|||
$rcE = new ReflectionClass('E'); |
|||
|
|||
$a1 = $rcA->newInstance(); |
|||
$a2 = $rcA->newInstance('x'); |
|||
var_dump($a1, $a2); |
|||
|
|||
$b1 = $rcB->newInstance(); |
|||
$b2 = $rcB->newInstance('x', 123); |
|||
var_dump($b1, $b2); |
|||
|
|||
try { |
|||
$rcC->newInstance(); |
|||
echo "you should not see this\n"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
try { |
|||
$rcD->newInstance(); |
|||
echo "you should not see this\n"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
$e1 = $rcE->newInstance(); |
|||
var_dump($e1); |
|||
|
|||
try { |
|||
$e2 = $rcE->newInstance('x'); |
|||
echo "you should not see this\n"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
In constructor of class A |
|||
In constructor of class A |
|||
object(A)#%d (0) { |
|||
} |
|||
object(A)#%d (0) { |
|||
} |
|||
|
|||
Warning: Missing argument 1 for B::__construct() in %s on line 9 |
|||
|
|||
Warning: Missing argument 2 for B::__construct() in %s on line 9 |
|||
|
|||
Notice: Undefined variable: a in %s on line 10 |
|||
|
|||
Notice: Undefined variable: b in %s on line 10 |
|||
In constructor of class B with args , |
|||
In constructor of class B with args x, 123 |
|||
object(B)#%d (0) { |
|||
} |
|||
object(B)#%d (0) { |
|||
} |
|||
Access to non-public constructor of class C |
|||
Access to non-public constructor of class D |
|||
object(E)#%d (0) { |
|||
} |
|||
Class E does not have a constructor, so you cannot pass any constructor arguments |
|||
@ -0,0 +1,77 @@ |
|||
--TEST-- |
|||
ReflectionClass::setStaticPropertyValue() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class A { |
|||
static private $privateOverridden = "original private"; |
|||
static protected $protectedOverridden = "original protected"; |
|||
static public $publicOverridden = "original public"; |
|||
} |
|||
|
|||
class B extends A { |
|||
static private $privateOverridden = "changed private"; |
|||
static protected $protectedOverridden = "changed protected"; |
|||
static public $publicOverridden = "changed public"; |
|||
} |
|||
|
|||
echo "Set static values in A:\n"; |
|||
$rcA = new ReflectionClass('A'); |
|||
$rcA->setStaticPropertyValue("\0A\0privateOverridden", "new value 1"); |
|||
$rcA->setStaticPropertyValue("\0*\0protectedOverridden", "new value 2"); |
|||
$rcA->setStaticPropertyValue("publicOverridden", "new value 3"); |
|||
print_r($rcA->getStaticProperties()); |
|||
|
|||
echo "\nSet static values in B:\n"; |
|||
$rcB = new ReflectionClass('B'); |
|||
$rcB->setStaticPropertyValue("\0A\0privateOverridden", "new value 4"); |
|||
$rcB->setStaticPropertyValue("\0B\0privateOverridden", "new value 5"); |
|||
$rcB->setStaticPropertyValue("\0*\0protectedOverridden", "new value 6"); |
|||
$rcB->setStaticPropertyValue("publicOverridden", "new value 7"); |
|||
print_r($rcA->getStaticProperties()); |
|||
print_r($rcB->getStaticProperties()); |
|||
|
|||
echo "\nSet non-existent values from A with no default value:\n"; |
|||
try { |
|||
var_dump($rcA->setStaticPropertyValue("protectedOverridden", "new value 8")); |
|||
echo "you should not see this"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
try { |
|||
var_dump($rcA->setStaticPropertyValue("privateOverridden", "new value 9")); |
|||
echo "you should not see this"; |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Set static values in A: |
|||
Array |
|||
( |
|||
[privateOverridden] => new value 1 |
|||
[protectedOverridden] => new value 2 |
|||
[publicOverridden] => new value 3 |
|||
) |
|||
|
|||
Set static values in B: |
|||
Array |
|||
( |
|||
[privateOverridden] => new value 4 |
|||
[protectedOverridden] => new value 2 |
|||
[publicOverridden] => new value 3 |
|||
) |
|||
Array |
|||
( |
|||
[privateOverridden] => new value 4 |
|||
[protectedOverridden] => new value 6 |
|||
[publicOverridden] => new value 7 |
|||
) |
|||
|
|||
Set non-existent values from A with no default value: |
|||
Class A does not have a property named protectedOverridden |
|||
Class A does not have a property named privateOverridden |
|||
@ -0,0 +1,60 @@ |
|||
--TEST-- |
|||
ReflectionClass::getStaticPropertyValue() - bad params |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C { |
|||
public static $x; |
|||
} |
|||
|
|||
$rc = new ReflectionClass('C'); |
|||
try { |
|||
var_dump($rc->setStaticPropertyValue("x", "default value", 'blah')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->setStaticPropertyValue()); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->setStaticPropertyValue(null)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->setStaticPropertyValue(null,null)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->setStaticPropertyValue(1.5, 'def')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($rc->setStaticPropertyValue(array(1,2,3), 'blah')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 3 given in %s on line 8 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 0 given in %s on line 13 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 1 given in %s on line 18 |
|||
NULL |
|||
Class C does not have a property named |
|||
Class C does not have a property named 1.5 |
|||
|
|||
Warning: ReflectionClass::setStaticPropertyValue() expects parameter 1 to be string, array given in %s on line 33 |
|||
NULL |
|||
@ -0,0 +1,224 @@ |
|||
--TEST-- |
|||
ReflectionClass::__toString() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
$rc = new ReflectionClass("ReflectionClass"); |
|||
echo $rc; |
|||
?> |
|||
--EXPECTF-- |
|||
Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { |
|||
|
|||
- Constants [3] { |
|||
Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 } |
|||
Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 } |
|||
Constant [ integer IS_FINAL ] { 64 } |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [1] { |
|||
Method [ <internal:Reflection> static public method export ] { |
|||
|
|||
- Parameters [2] { |
|||
Parameter #0 [ <required> $argument ] |
|||
Parameter #1 [ <optional> $return ] |
|||
} |
|||
} |
|||
} |
|||
|
|||
- Properties [1] { |
|||
Property [ <default> public $name ] |
|||
} |
|||
|
|||
- Methods [40] { |
|||
Method [ <internal:Reflection> final private method __clone ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection, ctor> public method __construct ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $argument ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method __toString ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getName ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isInternal ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isUserDefined ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isInstantiable ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getFileName ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getStartLine ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getEndLine ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getDocComment ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getConstructor ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method hasMethod ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $name ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getMethod ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $name ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getMethods ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <optional> $filter ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method hasProperty ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $name ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getProperty ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $name ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getProperties ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <optional> $filter ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method hasConstant ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $name ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getConstants ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getConstant ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $name ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getInterfaces ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getInterfaceNames ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isInterface ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isAbstract ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isFinal ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getModifiers ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isInstance ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $object ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method newInstance ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $args ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method newInstanceArgs ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <optional> array $args ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getParentClass ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isSubclassOf ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $class ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getStaticProperties ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getStaticPropertyValue ] { |
|||
|
|||
- Parameters [2] { |
|||
Parameter #0 [ <required> $name ] |
|||
Parameter #1 [ <optional> $default ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method setStaticPropertyValue ] { |
|||
|
|||
- Parameters [2] { |
|||
Parameter #0 [ <required> $name ] |
|||
Parameter #1 [ <required> $value ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getDefaultProperties ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method isIterateable ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method implementsInterface ] { |
|||
|
|||
- Parameters [1] { |
|||
Parameter #0 [ <required> $interface ] |
|||
} |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getExtension ] { |
|||
} |
|||
|
|||
Method [ <internal:Reflection> public method getExtensionName ] { |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
--TEST-- |
|||
ReflectionClass::__toString() - verify 'inherits', 'overwrites' and 'prototype' parts of method representation |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
Class A { |
|||
function f() {} |
|||
} |
|||
Class B extends A { |
|||
function f() {} |
|||
} |
|||
Class C extends B { |
|||
|
|||
} |
|||
Class D extends C { |
|||
function f() {} |
|||
} |
|||
foreach (array('A', 'B', 'C', 'D') as $class) { |
|||
echo "\n\n----( Reflection class $class: )----\n"; |
|||
$rc = new ReflectionClass($class); |
|||
echo $rc; |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
|
|||
----( Reflection class A: )---- |
|||
Class [ <user> class A ] { |
|||
@@ %s 2-4 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user> public method f ] { |
|||
@@ %s 3 - 3 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
----( Reflection class B: )---- |
|||
Class [ <user> class B extends A ] { |
|||
@@ %s 5-7 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user, overwrites A, prototype A> public method f ] { |
|||
@@ %s 6 - 6 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
----( Reflection class C: )---- |
|||
Class [ <user> class C extends B ] { |
|||
@@ %s 8-10 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user, inherits B, prototype A> public method f ] { |
|||
@@ %s 6 - 6 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
----( Reflection class D: )---- |
|||
Class [ <user> class D extends C ] { |
|||
@@ %s 11-13 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user, overwrites B, prototype A> public method f ] { |
|||
@@ %s 12 - 12 |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
--TEST-- |
|||
ReflectionClass::__toString() - verify 'inherits', 'overwrites' and 'prototype' parts of method representation with private methods |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
Class A { |
|||
private function f() {} |
|||
} |
|||
Class B extends A { |
|||
private function f() {} |
|||
} |
|||
Class C extends B { |
|||
|
|||
} |
|||
Class D extends C { |
|||
private function f() {} |
|||
} |
|||
foreach (array('A', 'B', 'C', 'D') as $class) { |
|||
echo "\n\n----( Reflection class $class: )----\n"; |
|||
$rc = new ReflectionClass($class); |
|||
echo $rc; |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
|
|||
----( Reflection class A: )---- |
|||
Class [ <user> class A ] { |
|||
@@ %s 2-4 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user> private method f ] { |
|||
@@ %s 3 - 3 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
----( Reflection class B: )---- |
|||
Class [ <user> class B extends A ] { |
|||
@@ %s 5-7 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user, overwrites A> private method f ] { |
|||
@@ %s 6 - 6 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
----( Reflection class C: )---- |
|||
Class [ <user> class C extends B ] { |
|||
@@ %s 8-10 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user, inherits B> private method f ] { |
|||
@@ %s 6 - 6 |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
----( Reflection class D: )---- |
|||
Class [ <user> class D extends C ] { |
|||
@@ %s 11-13 |
|||
|
|||
- Constants [0] { |
|||
} |
|||
|
|||
- Static properties [0] { |
|||
} |
|||
|
|||
- Static methods [0] { |
|||
} |
|||
|
|||
- Properties [0] { |
|||
} |
|||
|
|||
- Methods [1] { |
|||
Method [ <user, overwrites B> private method f ] { |
|||
@@ %s 12 - 12 |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
--TEST-- |
|||
ReflectionFunction methods |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
/** |
|||
* my doc comment |
|||
*/ |
|||
function foo () { |
|||
static $c; |
|||
static $a = 1; |
|||
static $b = "hello"; |
|||
$d = 5; |
|||
} |
|||
|
|||
/*** |
|||
* not a doc comment |
|||
*/ |
|||
function bar () {} |
|||
|
|||
|
|||
function dumpFuncInfo($name) { |
|||
$funcInfo = new ReflectionFunction($name); |
|||
var_dump($funcInfo->getName()); |
|||
var_dump($funcInfo->isInternal()); |
|||
var_dump($funcInfo->isUserDefined()); |
|||
var_dump($funcInfo->getStartLine()); |
|||
var_dump($funcInfo->getEndLine()); |
|||
var_dump($funcInfo->getStaticVariables()); |
|||
} |
|||
|
|||
dumpFuncInfo('foo'); |
|||
dumpFuncInfo('bar'); |
|||
dumpFuncInfo('extract'); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
string(3) "foo" |
|||
bool(false) |
|||
bool(true) |
|||
int(6) |
|||
int(11) |
|||
array(3) { |
|||
["c"]=> |
|||
NULL |
|||
["a"]=> |
|||
int(1) |
|||
["b"]=> |
|||
string(5) "hello" |
|||
} |
|||
string(3) "bar" |
|||
bool(false) |
|||
bool(true) |
|||
int(16) |
|||
int(16) |
|||
array(0) { |
|||
} |
|||
string(7) "extract" |
|||
bool(true) |
|||
bool(false) |
|||
bool(false) |
|||
bool(false) |
|||
array(0) { |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
--TEST-- |
|||
ReflectionFunction constructor errors |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
$a = new ReflectionFunction(array(1, 2, 3)); |
|||
try { |
|||
$a = new ReflectionFunction('nonExistentFunction'); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage(); |
|||
} |
|||
$a = new ReflectionFunction(); |
|||
$a = new ReflectionFunction(1, 2); |
|||
?> |
|||
--EXPECTF-- |
|||
Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d |
|||
Function nonExistentFunction() does not exist |
|||
Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d |
|||
|
|||
Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d |
|||
@ -0,0 +1,41 @@ |
|||
--TEST-- |
|||
ReflectionFunction::getDocComment() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
/** |
|||
* my doc comment |
|||
*/ |
|||
function foo () { |
|||
static $c; |
|||
static $a = 1; |
|||
static $b = "hello"; |
|||
$d = 5; |
|||
} |
|||
|
|||
/*** |
|||
* not a doc comment |
|||
*/ |
|||
function bar () {} |
|||
|
|||
|
|||
function dumpFuncInfo($name) { |
|||
$funcInfo = new ReflectionFunction($name); |
|||
var_dump($funcInfo->getDocComment()); |
|||
} |
|||
|
|||
dumpFuncInfo('foo'); |
|||
dumpFuncInfo('bar'); |
|||
dumpFuncInfo('extract'); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
string(%d) "/** |
|||
* my doc comment |
|||
*/" |
|||
bool(false) |
|||
bool(false) |
|||
|
|||
@ -0,0 +1,18 @@ |
|||
--TEST-- |
|||
ReflectionFunction::getFileName() with function in an included file |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
include "included4.inc"; |
|||
|
|||
$funcInfo = new ReflectionFunction('g'); |
|||
var_dump($funcInfo->getFileName()); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
%sincluded4.inc |
|||
%d |
|||
string(%d) "%sincluded4.inc" |
|||
@ -0,0 +1,39 @@ |
|||
--TEST-- |
|||
ReflectionFunction::getFileName() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
/** |
|||
* my doc comment |
|||
*/ |
|||
function foo () { |
|||
static $c; |
|||
static $a = 1; |
|||
static $b = "hello"; |
|||
$d = 5; |
|||
} |
|||
|
|||
/*** |
|||
* not a doc comment |
|||
*/ |
|||
function bar () {} |
|||
|
|||
|
|||
function dumpFuncInfo($name) { |
|||
$funcInfo = new ReflectionFunction($name); |
|||
var_dump($funcInfo->getFileName()); |
|||
} |
|||
|
|||
dumpFuncInfo('foo'); |
|||
dumpFuncInfo('bar'); |
|||
dumpFuncInfo('extract'); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
string(%d) "%sReflectionFunction_getFileName.002.php" |
|||
string(%d) "%sReflectionFunction_getFileName.002.php" |
|||
bool(false) |
|||
|
|||
@ -0,0 +1,100 @@ |
|||
--TEST-- |
|||
ReflectionMethod methods - wrong num args |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
var_dump(new ReflectionMethod()); |
|||
var_dump(new ReflectionMethod('a', 'b', 'c')); |
|||
|
|||
class C { |
|||
public function f() {} |
|||
} |
|||
|
|||
$rm = new ReflectionMethod('C', 'f'); |
|||
|
|||
var_dump($rm->isFinal(1)); |
|||
var_dump($rm->isAbstract(1)); |
|||
var_dump($rm->isPrivate(1)); |
|||
var_dump($rm->isProtected(1)); |
|||
var_dump($rm->isPublic(1)); |
|||
var_dump($rm->isStatic(1)); |
|||
var_dump($rm->isConstructor(1)); |
|||
var_dump($rm->isDestructor(1)); |
|||
var_dump($rm->getModifiers(1)); |
|||
var_dump($rm->isInternal(1)); |
|||
var_dump($rm->isUserDefined(1)); |
|||
var_dump($rm->getFileName(1)); |
|||
var_dump($rm->getStartLine(1)); |
|||
var_dump($rm->getEndLine(1)); |
|||
var_dump($rm->getStaticVariables(1)); |
|||
var_dump($rm->getName(1)); |
|||
|
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Warning: ReflectionMethod::__construct() expects %s on line 3 |
|||
object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(0) "" |
|||
["class"]=> |
|||
string(0) "" |
|||
} |
|||
|
|||
Warning: ReflectionMethod::__construct() expects %s on line 4 |
|||
object(ReflectionMethod)#%d (2) { |
|||
["name"]=> |
|||
string(0) "" |
|||
["class"]=> |
|||
string(0) "" |
|||
} |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isFinal() in %s on line 12 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isAbstract() in %s on line 13 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isPrivate() in %s on line 14 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isProtected() in %s on line 15 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isPublic() in %s on line 16 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isStatic() in %s on line 17 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isConstructor() in %s on line 18 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::isDestructor() in %s on line 19 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionMethod::getModifiers() in %s on line 20 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionFunctionAbstract::isInternal() in %s on line 21 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionFunctionAbstract::isUserDefined() in %s on line 22 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionFunctionAbstract::getFileName() in %s on line 23 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionFunctionAbstract::getStartLine() in %s on line 24 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionFunctionAbstract::getEndLine() in %s on line 25 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionFunctionAbstract::getStaticVariables() in %s on line 26 |
|||
NULL |
|||
|
|||
Warning: Wrong parameter count for ReflectionFunctionAbstract::getName() in %s on line 27 |
|||
NULL |
|||
@ -0,0 +1,103 @@ |
|||
--TEST-- |
|||
ReflectionMethod constructor errors |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
class TestClass |
|||
{ |
|||
public function foo() { |
|||
} |
|||
} |
|||
|
|||
|
|||
try { |
|||
echo "\nWrong type of argument (bool):\n"; |
|||
$methodInfo = new ReflectionMethod(true); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nWrong type of argument (int):\n"; |
|||
$methodInfo = new ReflectionMethod(3); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nWrong type of argument (bool, string):\n"; |
|||
$methodInfo = new ReflectionMethod(true, "foo"); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nWrong type of argument (string, bool):\n"; |
|||
$methodInfo = new ReflectionMethod('TestClass', true); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nNo method given:\n"; |
|||
$methodInfo = new ReflectionMethod("TestClass"); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nClass and Method in same string, bad method name:\n"; |
|||
$methodInfo = new ReflectionMethod("TestClass::foop::dedoop"); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nClass and Method in same string, bad class name:\n"; |
|||
$methodInfo = new ReflectionMethod("TestCla::foo"); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nClass and Method in same string (ok):\n"; |
|||
$methodInfo = new ReflectionMethod("TestClass::foo"); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Wrong type of argument (bool): |
|||
exception 'ReflectionException' with message 'Invalid method name 1' in %s |
|||
Stack trace: |
|||
#0 %s ReflectionMethod->__construct('1') |
|||
#1 {main} |
|||
Wrong type of argument (int): |
|||
exception 'ReflectionException' with message 'Invalid method name 3' in %s |
|||
Stack trace: |
|||
#0 %s ReflectionMethod->__construct('3') |
|||
#1 {main} |
|||
Wrong type of argument (bool, string): |
|||
exception 'ReflectionException' with message 'The parameter class is expected to be either a string or an object' in %s |
|||
Stack trace: |
|||
#0 %s ReflectionMethod->__construct(true, 'foo') |
|||
#1 {main} |
|||
Wrong type of argument (string, bool): |
|||
exception 'ReflectionException' with message 'Method TestClass::1() does not exist' in %s |
|||
Stack trace: |
|||
#0 %s ReflectionMethod->__construct('TestClass', '1') |
|||
#1 {main} |
|||
No method given: |
|||
exception 'ReflectionException' with message 'Invalid method name TestClass' in %s |
|||
Stack trace: |
|||
#0 %s ReflectionMethod->__construct('TestClass') |
|||
#1 {main} |
|||
Class and Method in same string, bad method name: |
|||
exception 'ReflectionException' with message 'Method TestClass::foop::dedoop() does not exist' in %s |
|||
Stack trace: |
|||
#0 %s ReflectionMethod->__construct('TestClass::foop...') |
|||
#1 {main} |
|||
Class and Method in same string, bad class name: |
|||
exception 'ReflectionException' with message 'Class TestCla does not exist' in %s |
|||
Stack trace: |
|||
#0 %s ReflectionMethod->__construct('TestCla::foo') |
|||
#1 {main} |
|||
Class and Method in same string (ok): |
|||
|
|||
@ -0,0 +1,37 @@ |
|||
--TEST-- |
|||
ReflectionMethod constructor errors |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
class TestClass |
|||
{ |
|||
public function foo() { |
|||
} |
|||
} |
|||
|
|||
|
|||
try { |
|||
echo "Too few arguments:\n"; |
|||
$methodInfo = new ReflectionMethod(); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
try { |
|||
echo "\nToo many arguments:\n"; |
|||
$methodInfo = new ReflectionMethod("TestClass", "foo", true); |
|||
} catch (Exception $e) { |
|||
print $e->__toString(); |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Too few arguments: |
|||
|
|||
Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12 |
|||
|
|||
Too many arguments: |
|||
|
|||
Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18 |
|||
@ -0,0 +1,48 @@ |
|||
--TEST-- |
|||
ReflectionObject::isSubclassOf() - bad arguments |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class C {} |
|||
$ro = new ReflectionObject(new C); |
|||
|
|||
echo "\n\nTest bad arguments:\n"; |
|||
try { |
|||
var_dump($ro->isSubclassOf()); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($ro->isSubclassOf('C', 'C')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($ro->isSubclassOf(null)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($ro->isSubclassOf('ThisClassDoesNotExist')); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
try { |
|||
var_dump($ro->isSubclassOf(2)); |
|||
} catch (Exception $e) { |
|||
echo $e->getMessage() . "\n"; |
|||
} |
|||
?> |
|||
--EXPECTF-- |
|||
Test bad arguments: |
|||
|
|||
Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 7 |
|||
NULL |
|||
|
|||
Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 12 |
|||
NULL |
|||
Parameter one must either be a string or a ReflectionClass object |
|||
Class ThisClassDoesNotExist does not exist |
|||
Parameter one must either be a string or a ReflectionClass object |
|||
@ -0,0 +1,80 @@ |
|||
--TEST-- |
|||
ReflectionParameter class - getNames() method. |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class ReflectTestClass { |
|||
public static function twoArgFunction($theIncrement, $anotherParam) { |
|||
return ++$theIncrement; |
|||
} |
|||
|
|||
public function oneArgNonStatic($theParam) { |
|||
$theParam--; |
|||
} |
|||
|
|||
public function noArgs() { |
|||
echo "No arg function\n"; |
|||
} |
|||
} |
|||
|
|||
// Create an instance of the Reflection_Method class |
|||
$method = new ReflectionMethod('ReflectTestClass', 'twoArgFunction'); |
|||
// Get the parameters |
|||
$parameters = $method->getParameters(); |
|||
echo "Parameters from twoArgMethod:\n\n"; |
|||
foreach($parameters as $parameter) { |
|||
var_dump($parameter); |
|||
$name = $parameter->getName(); |
|||
echo "\n"; |
|||
} |
|||
|
|||
$method = new ReflectionMethod('ReflectTestClass', 'oneArgNonStatic'); |
|||
$parameters = $method->getParameters(); |
|||
echo "Parameters from oneArgNonStatic:\n\n"; |
|||
foreach($parameters as $parameter) { |
|||
var_dump($parameter); |
|||
$name = $parameter->getName(); |
|||
echo "\n"; |
|||
} |
|||
|
|||
|
|||
$method = new ReflectionMethod('ReflectTestClass', 'noArgs'); |
|||
$parameters = $method->getParameters(); |
|||
echo "Parameters from noArgs:\n\n"; |
|||
var_dump($parameters); |
|||
foreach($parameters as $parameter) { |
|||
var_dump($parameter); |
|||
$name = $parameter->getName(); |
|||
echo "\n"; |
|||
} |
|||
|
|||
echo "done\n"; |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Parameters from twoArgMethod: |
|||
|
|||
object(ReflectionParameter)#%i (1) { |
|||
["name"]=> |
|||
string(12) "theIncrement" |
|||
} |
|||
|
|||
object(ReflectionParameter)#%i (1) { |
|||
["name"]=> |
|||
string(12) "anotherParam" |
|||
} |
|||
|
|||
Parameters from oneArgNonStatic: |
|||
|
|||
object(ReflectionParameter)#%i (1) { |
|||
["name"]=> |
|||
string(8) "theParam" |
|||
} |
|||
|
|||
Parameters from noArgs: |
|||
|
|||
array(0) { |
|||
} |
|||
done |
|||
@ -0,0 +1,80 @@ |
|||
--TEST-- |
|||
ReflectionParameter class - isPassedByReferenceMethod() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
class ReflectTestClass { |
|||
public static function staticMethod(&$paramOne, $anotherParam) { |
|||
return ++$theIncrement; |
|||
} |
|||
|
|||
public function instanceMethod($firstParam, &$secondParam) { |
|||
$firstParam = "Hello\n"; |
|||
} |
|||
} |
|||
|
|||
// Create an instance of the Reflection_Method class |
|||
$method = new ReflectionMethod('ReflectTestClass', 'staticMethod'); |
|||
// Get the parameters |
|||
$parameters = $method->getParameters(); |
|||
echo "Parameters from staticMethod:\n\n"; |
|||
foreach($parameters as $parameter) { |
|||
var_dump($parameter); |
|||
if($parameter->isPassedByReference()) { |
|||
echo "This param is passed by reference\n"; |
|||
} else { |
|||
echo "This param is not passed by reference\n"; |
|||
} |
|||
echo "\n"; |
|||
} |
|||
|
|||
// Create an instance of the Reflection_Method class |
|||
$method = new ReflectionMethod('ReflectTestClass', 'instanceMethod'); |
|||
// Get the parameters |
|||
$parameters = $method->getParameters(); |
|||
echo "Parameters from instanceMethod:\n\n"; |
|||
foreach($parameters as $parameter) { |
|||
var_dump($parameter); |
|||
if($parameter->isPassedByReference()) { |
|||
echo "This param is passed by reference\n"; |
|||
} else { |
|||
echo "This param is not passed by reference\n"; |
|||
} |
|||
echo "\n"; |
|||
} |
|||
|
|||
echo "done\n"; |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Parameters from staticMethod: |
|||
|
|||
object(ReflectionParameter)#%i (1) { |
|||
["name"]=> |
|||
string(8) "paramOne" |
|||
} |
|||
This param is passed by reference |
|||
|
|||
object(ReflectionParameter)#%i (1) { |
|||
["name"]=> |
|||
string(12) "anotherParam" |
|||
} |
|||
This param is not passed by reference |
|||
|
|||
Parameters from instanceMethod: |
|||
|
|||
object(ReflectionParameter)#%i (1) { |
|||
["name"]=> |
|||
string(10) "firstParam" |
|||
} |
|||
This param is not passed by reference |
|||
|
|||
object(ReflectionParameter)#%i (1) { |
|||
["name"]=> |
|||
string(11) "secondParam" |
|||
} |
|||
This param is passed by reference |
|||
|
|||
done |
|||
@ -0,0 +1,88 @@ |
|||
--TEST-- |
|||
ReflectionParameter class - isOptional, isDefaultValueAvailable and getDefaultValue methods. |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
class ReflectTestClass { |
|||
public static function staticMethod($paramOne, $anotherParam = "bob", |
|||
&$thirdParam = "jack", $arrayParam = array('one')) { |
|||
echo "hello from test\n"; |
|||
echo "third is $thirdParam\n"; |
|||
return ++$theIncrement; |
|||
} |
|||
|
|||
} |
|||
|
|||
$jane = "jane"; |
|||
ReflectTestClass::staticMethod("bob", "jack"); |
|||
|
|||
$refMethod = new ReflectionMethod('ReflectTestClass', 'staticMethod'); |
|||
$refParameters = $refMethod->getParameters(); |
|||
|
|||
echo "parameter names from staticMethod method:\n\n"; |
|||
foreach($refParameters as $parameter) { |
|||
var_dump($parameter); |
|||
if($parameter->isOptional()) { |
|||
echo "this parameter is optional\n"; |
|||
} else { |
|||
echo "this parameter is not optional\n"; |
|||
} |
|||
|
|||
if($parameter->isDefaultValueAvailable()) { |
|||
echo "this parameter has a default value\n"; |
|||
} else { |
|||
echo "this parameter has no default value\n"; |
|||
} |
|||
|
|||
/* |
|||
$val = 0; |
|||
try { |
|||
$val = $parameter->getDefaultValue(); |
|||
var_dump($val); |
|||
} catch (ReflectionException $e) { |
|||
print $e->getMessage(); |
|||
echo "\n"; |
|||
} |
|||
*/ |
|||
|
|||
echo "\n"; |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
hello from test |
|||
third is jack |
|||
|
|||
Notice: Undefined variable: theIncrement in %s on line 8 |
|||
parameter names from staticMethod method: |
|||
|
|||
object(ReflectionParameter)#%d (1) { |
|||
["name"]=> |
|||
string(8) "paramOne" |
|||
} |
|||
this parameter is not optional |
|||
this parameter has no default value |
|||
|
|||
object(ReflectionParameter)#%d (1) { |
|||
["name"]=> |
|||
string(12) "anotherParam" |
|||
} |
|||
this parameter is optional |
|||
this parameter has a default value |
|||
|
|||
object(ReflectionParameter)#%d (1) { |
|||
["name"]=> |
|||
string(10) "thirdParam" |
|||
} |
|||
this parameter is optional |
|||
this parameter has a default value |
|||
|
|||
object(ReflectionParameter)#%d (1) { |
|||
["name"]=> |
|||
string(10) "arrayParam" |
|||
} |
|||
this parameter is optional |
|||
this parameter has a default value |
|||
@ -0,0 +1,66 @@ |
|||
--TEST-- |
|||
ReflectionProperty::getModifiers() |
|||
--CREDITS-- |
|||
Robin Fernandes <robinf@php.net> |
|||
Steve Seear <stevseea@php.net> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function reflectProperty($class, $property) { |
|||
$propInfo = new ReflectionProperty($class, $property); |
|||
|
|||
echo "**********************************\n"; |
|||
echo "Reflecting on property $class::$property\n\n"; |
|||
|
|||
echo "getModifiers():\n"; |
|||
var_dump($propInfo->getModifiers()); |
|||
|
|||
echo "\n**********************************\n"; |
|||
} |
|||
|
|||
class TestClass |
|||
{ |
|||
public $pub; |
|||
static public $stat = "static property"; |
|||
/** |
|||
* This property has a comment. |
|||
*/ |
|||
protected $prot = 4; |
|||
private $priv = "keepOut"; |
|||
} |
|||
|
|||
reflectProperty("TestClass", "pub"); |
|||
reflectProperty("TestClass", "stat"); |
|||
reflectProperty("TestClass", "prot"); |
|||
reflectProperty("TestClass", "priv"); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
********************************** |
|||
Reflecting on property TestClass::pub |
|||
|
|||
getModifiers(): |
|||
int(256) |
|||
|
|||
********************************** |
|||
********************************** |
|||
Reflecting on property TestClass::stat |
|||
|
|||
getModifiers(): |
|||
int(257) |
|||
|
|||
********************************** |
|||
********************************** |
|||
Reflecting on property TestClass::prot |
|||
|
|||
getModifiers(): |
|||
int(512) |
|||
|
|||
********************************** |
|||
********************************** |
|||
Reflecting on property TestClass::priv |
|||
|
|||
getModifiers(): |
|||
int(1024) |
|||
|
|||
********************************** |
|||
@ -0,0 +1,9 @@ |
|||
<?php |
|||
echo __FILE__ . "\n"; |
|||
echo __LINE__ . "\n"; |
|||
|
|||
function g() { |
|||
echo __FILE__ . "\n"; |
|||
echo __LINE__ . "\n"; |
|||
} |
|||
?> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue