php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41088 PHP will not perform break() outside of loop(s)
Submitted: 2007-04-14 23:08 UTC Modified: 2007-04-15 00:07 UTC
From: barryd dot it at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.1 OS: Irrelevent
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: barryd dot it at gmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-14 23:15 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

A function has another execution scope.
 [2007-04-14 23:34 UTC] barryd dot it at gmail dot com
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?
 [2007-04-14 23:42 UTC] barryd dot it at gmail dot com
<?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!
 [2007-04-14 23:51 UTC] barryd dot it at gmail dot com
Please review this again...
 [2007-04-15 00:07 UTC] scottmac@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

break would be within the scope of the function, not within the scope of the loop.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 23:00:01 2025 UTC