Query on assert_options() api
| From: | Andy Wharmby | Date: | Wed, 20 Dec 2006 18:00:33 +0000 |
| Subject: | Query on assert_options() api | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-27151@lists.php.net to get a copy of this message | ||
Hi Internals
A colleague of mine is currently working on creating new test
cases to improve the coverage of the PHP test cases and whilst
attempting to
write new tests for the assert extension hit on a problem when
attempting to query the current setting of ASSERT_CALLBACK. using the
assert_options() api.
With the following simple testcase :
<?php
function andy()
{
echo "andy called\n";
}
$o = assert_options(ASSERT_CALLBACK, "andy"); /* SET */
$n = assert_options(ASSERT_CALLBACK); /* INQ */
echo "old setting is $o\n";
echo "new setting is $n\n";
?>
The expected result was that the old (if any) and new setting of the
callback function name would be displayed but the actual results was
old setting is 1
new setting is 1
Looking at the code this is no surprise as the code in assert.c which
processes these requests unconditionally returns with RETURN_TRUE.
For all other assert options other than assert_options() function
returns the old value of the specified option as documented in the PHP
manual.
Further investigation uncovered that the code actually did behave in the
way we expected until it was changed to accept the array(&$obj,
"methodname")
syntax back in July 2001 (revision 1.32 of assert.c). At this time the
return was changed to be unconditionally TRUE.
Unfortunately this makes writing a test case to query the current
setting of the ASSERT_CALLBACK option impossible as assert_options() no
longer returns
any useable information for this option, i.e to code a testcase as
above that sets a value and then checks its set as expected.
If the code is modified as in the attached patch to instead return the
ZVAL for the ASSERT_CALLBACK option then we are able create the new
testcase to
verify the assert_options() api. However, I am concerned there is a
good reason this was not done when the code was changed back in 2001.Can
anyone think
of a good reason why returning the zval on this api is not a good idea ?
Any comments on my proposed fix appreciated.
Regards
Andy
Andy Wharmby
IBM United Kingdom Limited