summaryrefslogtreecommitdiff
path: root/ext/reflection/tests/ReflectionParameter_003.phpt
diff options
context:
space:
mode:
authorAnt Phillips <ant@php.net>2008-11-18 15:37:57 +0000
committerAnt Phillips <ant@php.net>2008-11-18 15:37:57 +0000
commitddb2c0584149313d80fbec89f01264338b0073b7 (patch)
treef5251b8af450d59bf19ce6de2d7a7cdd5dd78a10 /ext/reflection/tests/ReflectionParameter_003.phpt
parentf305ddbe537005997dccc00e9057de42a76cf631 (diff)
downloadphp-git-ddb2c0584149313d80fbec89f01264338b0073b7.tar.gz
Reflection tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit).
Diffstat (limited to 'ext/reflection/tests/ReflectionParameter_003.phpt')
-rw-r--r--ext/reflection/tests/ReflectionParameter_003.phpt88
1 files changed, 88 insertions, 0 deletions
diff --git a/ext/reflection/tests/ReflectionParameter_003.phpt b/ext/reflection/tests/ReflectionParameter_003.phpt
new file mode 100644
index 0000000000..5dfc213a67
--- /dev/null
+++ b/ext/reflection/tests/ReflectionParameter_003.phpt
@@ -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) {
+ [u"name"]=>
+ unicode(8) "paramOne"
+}
+this parameter is not optional
+this parameter has no default value
+
+object(ReflectionParameter)#%d (1) {
+ [u"name"]=>
+ unicode(12) "anotherParam"
+}
+this parameter is optional
+this parameter has a default value
+
+object(ReflectionParameter)#%d (1) {
+ [u"name"]=>
+ unicode(10) "thirdParam"
+}
+this parameter is optional
+this parameter has a default value
+
+object(ReflectionParameter)#%d (1) {
+ [u"name"]=>
+ unicode(10) "arrayParam"
+}
+this parameter is optional
+this parameter has a default value