|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-04-14 23:08 UTC] barryd dot it at gmail dot com
Description:
------------
Ok, I can not perform a break(); by using a $var = create_function('', 'break;'); outside of loop(s).
In comparision, I am able to define a variable with the value 'Hello World', and use that variable anywhere within the global script bounderies. That being said and done, the following should be possible...
Reproduce code:
---------------
<?php
$func = create_function('', 'break;');
while(1) {
sleep(1);
while(1) {
$func();
}
echo 'hello world' . "\n";
}
exit();
?>
Expected result:
----------------
I would expect the result would be a continuous return of Hello world w/ a line break.
Now, I understand the first person too respond will say "...the break is resulting not within the boundries of an actual loop...".
If you were to have it do echo "this is a break"; ... then the code should not actually be executing, but instead defining its self to a variable, to be used later on in the script.
Actual result:
--------------
PHP Fatal error: Cannot break/continue 1 level in /home/barryd/Projects/PHP/phpMini/test.php(2) : runtime-created function on line 1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 22:00:01 2025 UTC |
This is not a problem with the scope... If a variable can have the definition of a create_function('', 'echo "This is where the break is\n"'); Then technically speaking, a break(); should be existent from within this function, and not have actually resulted/occured without the variable function being called for... Lamens term: If I can tell php to return a value, before the required moment for that result, then a break(); function should occure in the same means... What is so troubling about this idea?<?php $func = create_function('', 'echo "this is the break\n";'); while(1) { while(1) { sleep(1); $func(); } echo 'hello world' . "\n"; } exit(); ?> The result is a continuous loop of 'this is a break\n', which means that the echo function is being performed after the variable defintion, which would mean that any other function should occure in the same result!