helly           Sun Mar 12 17:22:34 2006 UTC

  Added files:                 (Branch: PHP_5_1)
    /php-src/ext/reflection/tests       parameters_002.phpt 

  Modified files:              
    /php-src/ext/reflection     php_reflection.c 
    /php-src/ext/reflection/tests       bug26695.phpt bug29268.phpt 
  Log:
  - MFH:
  - Fix ReflectionParameter
    . Reintroduce getClass()
    . Change getDeclaringClass() to return what it suggests
    . (inactive but tested) Add getDeclaringFunction()
    . (inactive but tested) Add getPosition()
  - Fix tests accordingly
  # This also fixes Bug #36687 ReflectionParameter::getDeclaringClass returns
  # wrong result
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/reflection/php_reflection.c?r1=1.164.2.31&r2=1.164.2.32&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.164.2.31 
php-src/ext/reflection/php_reflection.c:1.164.2.32
--- php-src/ext/reflection/php_reflection.c:1.164.2.31  Mon Mar  6 23:26:28 2006
+++ php-src/ext/reflection/php_reflection.c     Sun Mar 12 17:22:34 2006
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_reflection.c,v 1.164.2.31 2006/03/06 23:26:28 rasmus Exp $ */
+/* $Id: php_reflection.c,v 1.164.2.32 2006/03/12 17:22:34 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1787,6 +1787,7 @@
                                }
                                efree(lcname);
                        }
+                       ce = fptr->common.scope;
                        break;
 
                case IS_ARRAY: {
@@ -1901,9 +1902,10 @@
 }
 /* }}} */
 
-/* {{{ proto public ReflectionClass ReflectionParameter::getDeclaringClass()
-   Returns this parameters's class hint or NULL if there is none */
-ZEND_METHOD(reflection_parameter, getDeclaringClass)
+#if MBO_0
+/* {{{ proto public ReflectionFunction 
ReflectionParameter::getDeclaringFunction()
+   Returns the ReflectionFunction for the function of this parameter */
+ZEND_METHOD(reflection_parameter, getDeclaringFunction)
 {
        reflection_object *intern;
        parameter_reference *param;
@@ -1911,12 +1913,44 @@
        METHOD_NOTSTATIC_NUMPARAMS(reflection_parameter_ptr, 0);
        GET_REFLECTION_OBJECT_PTR(param);
 
-       if (!param->arg_info->class_name) {
-               RETURN_NULL();
+       if (!param->fptr->common.scope) {
+               reflection_function_factory(param->fptr, return_value 
TSRMLS_CC);
        } else {
-               zend_class_entry **pce;
+               reflection_method_factory(param->fptr->common.scope, 
param->fptr, return_value TSRMLS_CC);
+       }
+}
+/* }}} */
+#endif
+
+/* {{{ proto public ReflectionClass|NULL 
ReflectionParameter::getDeclaringClass()
+   Returns in which class this parameter is defined (not the typehint of the 
parameter) */
+ZEND_METHOD(reflection_parameter, getDeclaringClass)
+{
+       reflection_object *intern;
+       parameter_reference *param;
+
+       METHOD_NOTSTATIC_NUMPARAMS(reflection_parameter_ptr, 0);
+       GET_REFLECTION_OBJECT_PTR(param);
+
+       if (param->fptr->common.scope) {
+               zend_reflection_class_factory(param->fptr->common.scope, 
return_value TSRMLS_CC);
+       }       
+}
+/* }}} */
+
+/* {{{ proto public ReflectionClass|NULL ReflectionParameter::getClass()
+   Returns this parameters's class hint or NULL if there is none */
+ZEND_METHOD(reflection_parameter, getClass)
+{
+       reflection_object *intern;
+       parameter_reference *param;
+       zend_class_entry **pce;
+
+       METHOD_NOTSTATIC_NUMPARAMS(reflection_parameter_ptr, 0);
+       GET_REFLECTION_OBJECT_PTR(param);
 
-               if (zend_lookup_class_ex(param->arg_info->class_name, 
param->arg_info->class_name_len, 1, &pce TSRMLS_CC) == FAILURE) {
+       if (param->arg_info->class_name) {
+               if (zend_lookup_class(param->arg_info->class_name, 
param->arg_info->class_name_len, &pce TSRMLS_CC) == FAILURE) {
                        zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC, 
                                "Class %s does not exist", 
param->arg_info->class_name);
                        return;
@@ -1968,6 +2002,22 @@
 }
 /* }}} */
 
+#if MBO_0
+/* {{{ proto public bool ReflectionParameter::getPosition()
+   Returns whether this parameter is an optional parameter */
+ZEND_METHOD(reflection_parameter, getPosition)
+{
+       reflection_object *intern;
+       parameter_reference *param;
+
+       METHOD_NOTSTATIC_NUMPARAMS(reflection_parameter_ptr, 0);
+       GET_REFLECTION_OBJECT_PTR(param);
+
+       RETVAL_LONG(param->offset);
+}
+/* }}} */
+#endif
+
 /* {{{ proto public bool ReflectionParameter::isOptional()
    Returns whether this parameter is an optional parameter */
 ZEND_METHOD(reflection_parameter, isOptional)
@@ -4295,10 +4345,16 @@
        ZEND_ME(reflection_parameter, __toString, NULL, 0)
        ZEND_ME(reflection_parameter, getName, NULL, 0)
        ZEND_ME(reflection_parameter, isPassedByReference, NULL, 0)
+#if MBO_0
+       ZEND_ME(reflection_parameter, getDeclaringFunction, NULL, 0)
+#endif
        ZEND_ME(reflection_parameter, getDeclaringClass, NULL, 0)
-       ZEND_MALIAS(reflection_parameter, getClass, getDeclaringClass, NULL, 
ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
+       ZEND_ME(reflection_parameter, getClass, NULL, 0)
        ZEND_ME(reflection_parameter, isArray, NULL, 0)
        ZEND_ME(reflection_parameter, allowsNull, NULL, 0)
+#if MBO_0
+       ZEND_ME(reflection_parameter, getPosition, NULL, 0)
+#endif
        ZEND_ME(reflection_parameter, isOptional, NULL, 0)
        ZEND_ME(reflection_parameter, isDefaultValueAvailable, NULL, 0)
        ZEND_ME(reflection_parameter, getDefaultValue, NULL, 0)
@@ -4432,7 +4488,7 @@
        php_info_print_table_start();
        php_info_print_table_header(2, "Reflection", "enabled");
 
-       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 
1.164.2.31 2006/03/06 23:26:28 rasmus Exp $");
+       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 
1.164.2.32 2006/03/12 17:22:34 helly Exp $");
 
        php_info_print_table_end();
 } /* }}} */
http://cvs.php.net/viewcvs.cgi/php-src/ext/reflection/tests/bug26695.phpt?r1=1.2.4.2&r2=1.2.4.3&diff_format=u
Index: php-src/ext/reflection/tests/bug26695.phpt
diff -u php-src/ext/reflection/tests/bug26695.phpt:1.2.4.2 
php-src/ext/reflection/tests/bug26695.phpt:1.2.4.3
--- php-src/ext/reflection/tests/bug26695.phpt:1.2.4.2  Sun Mar 12 12:38:25 2006
+++ php-src/ext/reflection/tests/bug26695.phpt  Sun Mar 12 17:22:34 2006
@@ -17,7 +17,7 @@
 $methods = $class->getMethods();
 $params = $methods[0]->getParameters();
 
-$class = $params[0]->getDeclaringClass();
+$class = $params[0]->getClass();
 
 var_dump($class->getName());
 ?>
http://cvs.php.net/viewcvs.cgi/php-src/ext/reflection/tests/bug29268.phpt?r1=1.1.2.3&r2=1.1.2.4&diff_format=u
Index: php-src/ext/reflection/tests/bug29268.phpt
diff -u php-src/ext/reflection/tests/bug29268.phpt:1.1.2.3 
php-src/ext/reflection/tests/bug29268.phpt:1.1.2.4
--- php-src/ext/reflection/tests/bug29268.phpt:1.1.2.3  Sun Mar 12 12:38:25 2006
+++ php-src/ext/reflection/tests/bug29268.phpt  Sun Mar 12 17:22:34 2006
@@ -16,8 +16,9 @@
 
 $ref = new reflectionMethod('B','doit');
 $parameters = $ref->getParameters();   
-foreach($parameters as $parameter){
-       $class = $parameter->getDeclaringClass();       
+foreach($parameters as $parameter)
+{
+       $class = $parameter->getClass();
        echo $class->name."\n";
 }
 echo "ok\n";

http://cvs.php.net/viewcvs.cgi/php-src/ext/reflection/tests/parameters_002.phpt?view=markup&rev=1.1
Index: php-src/ext/reflection/tests/parameters_002.phpt
+++ php-src/ext/reflection/tests/parameters_002.phpt
--TEST--
ReflectionParameter::getclass(), getDeclaringClass(), getDeclaringFunction()
--SKIPIF--
<?php extension_loaded('reflection') or die('skip'); ?>
--FILE--
<?php

function test($nix, Array $ar, &$ref, stdClass $std, NonExistingClass $na, 
stdClass &$opt = NULL, $def = "FooBar")
{
}

class test
{
        function test($nix, Array $ar, &$ref, stdClass $std, NonExistingClass 
$na, stdClass $opt = NULL, $def = "FooBar")
        {
        }
}

function check_params_decl_func($r, $f)
{
        $c = $r->$f();
        echo $f . ': ' . ($c ? ($c instanceof ReflectionMethod ? $c->class . 
'::' : '') . $c->name : 'NULL') . "()\n";
}

function check_params_decl_class($r, $f)
{
        $c = $r->$f();
        echo $f . ': ' . ($c ? $c->name : 'NULL') . "\n";
}

function check_params_func($r, $f)
{
        echo $f . ': ';
        $v = $r->$f();
        var_dump($v);
}

function check_params($r)
{
        echo "#####" . ($r instanceof ReflectionMethod ? $r->class . '::' : '') 
. $r->name . "()#####\n";
        foreach($r->getParameters() as $p)
        {
                echo "===" . $p->getPosition() . "===\n";
                check_params_func($p, 'getName');
                check_params_func($p, 'isPassedByReference');
                try
                {
                        check_params_decl_class($p, 'getClass');
                }
                catch(ReflectionException $e)
                {
                        echo $e->getMessage() . "\n";
                }
                check_params_decl_class($p, 'getDeclaringClass');
                check_params_decl_func($p, 'getDeclaringFunction');
                check_params_func($p, 'isArray');
                check_params_func($p, 'allowsNull');
                check_params_func($p, 'isOptional');
                check_params_func($p, 'isDefaultValueAvailable');
                if ($p->isOptional())
                {
                        check_params_func($p, 'getDefaultValue');
                }
        }
}

check_params(new ReflectionFunction('test'));

check_params(new ReflectionMethod('test::test'));

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
#####test()#####
===0===
getName: string(3) "nix"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===1===
getName: string(2) "ar"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(true)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===2===
getName: string(3) "ref"
isPassedByReference: bool(true)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===3===
getName: string(3) "std"
isPassedByReference: bool(false)
getClass: stdClass
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===4===
getName: string(2) "na"
isPassedByReference: bool(false)
Class NonExistingClass does not exist
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===5===
getName: string(3) "opt"
isPassedByReference: bool(true)
getClass: stdClass
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: NULL
===6===
getName: string(3) "def"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: string(6) "FooBar"
#####test::test()#####
===0===
getName: string(3) "nix"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===1===
getName: string(2) "ar"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(true)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===2===
getName: string(3) "ref"
isPassedByReference: bool(true)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===3===
getName: string(3) "std"
isPassedByReference: bool(false)
getClass: stdClass
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===4===
getName: string(2) "na"
isPassedByReference: bool(false)
Class NonExistingClass does not exist
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===5===
getName: string(3) "opt"
isPassedByReference: bool(false)
getClass: stdClass
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: NULL
===6===
getName: string(3) "def"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: string(6) "FooBar"
===DONE===
--UEXPECT--
#####test()#####
===0===
getName: unicode(3) "nix"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===1===
getName: unicode(2) "ar"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(true)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===2===
getName: unicode(3) "ref"
isPassedByReference: bool(true)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===3===
getName: unicode(3) "std"
isPassedByReference: bool(false)
getClass: stdClass
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===4===
getName: unicode(2) "na"
isPassedByReference: bool(false)
Class NonExistingClass does not exist
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===5===
getName: unicode(3) "opt"
isPassedByReference: bool(true)
getClass: stdClass
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: NULL
===6===
getName: unicode(3) "def"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: NULL
getDeclaringFunction: test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: unicode(6) "FooBar"
#####test::test()#####
===0===
getName: unicode(3) "nix"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===1===
getName: unicode(2) "ar"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(true)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===2===
getName: unicode(3) "ref"
isPassedByReference: bool(true)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===3===
getName: unicode(3) "std"
isPassedByReference: bool(false)
getClass: stdClass
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===4===
getName: unicode(2) "na"
isPassedByReference: bool(false)
Class NonExistingClass does not exist
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(false)
isOptional: bool(false)
isDefaultValueAvailable: bool(false)
===5===
getName: unicode(3) "opt"
isPassedByReference: bool(false)
getClass: stdClass
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: NULL
===6===
getName: unicode(3) "def"
isPassedByReference: bool(false)
getClass: NULL
getDeclaringClass: test
getDeclaringFunction: test::test()
isArray: bool(false)
allowsNull: bool(true)
isOptional: bool(true)
isDefaultValueAvailable: bool(true)
getDefaultValue: unicode(6) "FooBar"
===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to