hi Gustavo, I'm not sure it makes sense to add a method to do the opposite of ::isPassedByReference. I'm also not sure about ZEND_SEND_PREFER_REF being considered as by value in your implementation.
What is the logic/reasoning behind this addition? Cheers, 2010/10/26 Gustavo André dos Santos Lopes <cataphr...@php.net>: > cataphract Tue, 26 Oct 2010 15:01:36 +0000 > > Revision: http://svn.php.net/viewvc?view=revision&revision=304920 > > Log: > - Added ReflectionParameter::canBePassedByValue(). > > Changed paths: > U php/php-src/trunk/UPGRADING > U php/php-src/trunk/ext/reflection/php_reflection.c > A > php/php-src/trunk/ext/reflection/tests/ReflectionParameter_canBePassedByValue.phpt > > Modified: php/php-src/trunk/UPGRADING > =================================================================== > --- php/php-src/trunk/UPGRADING 2010-10-26 12:40:48 UTC (rev 304919) > +++ php/php-src/trunk/UPGRADING 2010-10-26 15:01:36 UTC (rev 304920) > @@ -299,6 +299,7 @@ > - ReflectionClass::getTraits() > - ReflectionClass::getTraitNames() > - ReflectionClass::getTraitAliases() > + - ReflectionParameter::canBePassedByValue() > > - PDO_dblib > - PDO::newRowset() > > Modified: php/php-src/trunk/ext/reflection/php_reflection.c > =================================================================== > --- php/php-src/trunk/ext/reflection/php_reflection.c 2010-10-26 12:40:48 > UTC (rev 304919) > +++ php/php-src/trunk/ext/reflection/php_reflection.c 2010-10-26 15:01:36 > UTC (rev 304920) > @@ -2519,6 +2519,23 @@ > } > /* }}} */ > > +/* {{{ proto public bool ReflectionParameter::canBePassedByValue() > + Returns whether this parameter can be passed by value */ > +ZEND_METHOD(reflection_parameter, canBePassedByValue) > +{ > + reflection_object *intern; > + parameter_reference *param; > + > + if (zend_parse_parameters_none() == FAILURE) { > + return; > + } > + GET_REFLECTION_OBJECT_PTR(param); > + > + /* true if it's ZEND_SEND_BY_VAL or ZEND_SEND_PREFER_REF */ > + RETVAL_BOOL(param->arg_info->pass_by_reference != ZEND_SEND_BY_REF); > +} > +/* }}} */ > + > /* {{{ proto public bool ReflectionParameter::getPosition() > Returns whether this parameter is an optional parameter */ > ZEND_METHOD(reflection_parameter, getPosition) > @@ -5901,6 +5918,7 @@ > ZEND_ME(reflection_parameter, __toString, arginfo_reflection__void, 0) > ZEND_ME(reflection_parameter, getName, arginfo_reflection__void, 0) > ZEND_ME(reflection_parameter, isPassedByReference, > arginfo_reflection__void, 0) > + ZEND_ME(reflection_parameter, canBePassedByValue, > arginfo_reflection__void, 0) > ZEND_ME(reflection_parameter, getDeclaringFunction, > arginfo_reflection__void, 0) > ZEND_ME(reflection_parameter, getDeclaringClass, > arginfo_reflection__void, 0) > ZEND_ME(reflection_parameter, getClass, arginfo_reflection__void, 0) > > Added: > php/php-src/trunk/ext/reflection/tests/ReflectionParameter_canBePassedByValue.phpt > =================================================================== > --- > php/php-src/trunk/ext/reflection/tests/ReflectionParameter_canBePassedByValue.phpt > (rev 0) > +++ > php/php-src/trunk/ext/reflection/tests/ReflectionParameter_canBePassedByValue.phpt > 2010-10-26 15:01:36 UTC (rev 304920) > @@ -0,0 +1,84 @@ > +--TEST-- > +ReflectionParameter class - canBePassedByValue() method. > +--FILE-- > +<?php > + > +function aux($fun) { > + > + $func = new ReflectionFunction($fun); > + $parameters = $func->getParameters(); > + foreach($parameters as $parameter) { > + echo "Name: ", $parameter->getName(), "\n"; > + echo "Is passed by reference: ", > $parameter->isPassedByReference()?"yes":"no", "\n"; > + echo "Can be passed by value: ", > $parameter->canBePassedByValue()?"yes":"no", "\n"; > + echo "\n"; > + } > + > +} > + > +echo "=> array_multisort:\n\n"; > + > +aux('array_multisort'); > + > + > +echo "=> sort:\n\n"; > + > +aux('sort'); > + > +echo "=> user function:\n\n"; > + > +function ufunc(&$arg1, $arg2) {} > + > +aux('ufunc'); > + > +echo "Done.\n"; > + > +?> > +--EXPECTF-- > +=> array_multisort: > + > +Name: arr1 > +Is passed by reference: yes > +Can be passed by value: yes > + > +Name: SORT_ASC_or_SORT_DESC > +Is passed by reference: yes > +Can be passed by value: yes > + > +Name: SORT_REGULAR_or_SORT_NUMERIC_or_SORT_STRING > +Is passed by reference: yes > +Can be passed by value: yes > + > +Name: arr2 > +Is passed by reference: yes > +Can be passed by value: yes > + > +Name: SORT_ASC_or_SORT_DESC > +Is passed by reference: yes > +Can be passed by value: yes > + > +Name: SORT_REGULAR_or_SORT_NUMERIC_or_SORT_STRING > +Is passed by reference: yes > +Can be passed by value: yes > + > +=> sort: > + > +Name: arg > +Is passed by reference: yes > +Can be passed by value: no > + > +Name: sort_flags > +Is passed by reference: no > +Can be passed by value: yes > + > +=> user function: > + > +Name: arg1 > +Is passed by reference: yes > +Can be passed by value: no > + > +Name: arg2 > +Is passed by reference: no > +Can be passed by value: yes > + > +Done. > > > -- > PHP CVS Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php