note 78176 added to function.assert
| From: | Krzysztof' | Date: | Tue, 02 Oct 2007 01:13:06 +0000 |
| Subject: | note 78176 added to function.assert | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130974@lists.php.net to get a copy of this message | ||
Note that func_get_args() should be used carefully and never in a string! For example:
<?php
function asserted_normal($a, $b) {
assert(var_dump(func_get_args()));
}
function asserted_string($a, $b) {
assert('var_dump(func_get_args())');
}
?>
<?php asserted_normal(1,2) ?> prints
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
but <?php asserted_string(3,4) ?> prints
array(1) {
[0]=>
string(25) "var_dump(func_get_args())"
}
This is because of that the string passed to assert() is being evaled inside assert, and not your
function. Also, note that this works correctly, because of the eval scope:
<?php
function asserted_evaled_string($a, $b) {
assert(eval('var_dump(func_get_args())'));
}
asserted_evaled_string(5,6);
?>
array(2) {
[0]=>
int(5)
[1]=>
int(6)
}
(oh, and for simplicity's sake the evaled code doesn't return true, so don't worry
that it fails assertion...)
----
Server IP: 82.160.94.10
Probable Submitter: 83.15.56.98
----
Manual Page -- http://www.php.net/manual/en/function.assert.php
Edit -- https://master.php.net/note/edit/78176
Del: integrated -- https://master.php.net/note/delete/78176/integrated
Del: useless -- https://master.php.net/note/delete/78176/useless
Del: bad code -- https://master.php.net/note/delete/78176/bad+code
Del: spam -- https://master.php.net/note/delete/78176/spam
Del: non-english -- https://master.php.net/note/delete/78176/non-english
Del: in docs -- https://master.php.net/note/delete/78176/in+docs
Del: other reasons-- https://master.php.net/note/delete/78176
Reject -- https://master.php.net/note/reject/78176
Search -- https://master.php.net/manage/user-notes.php