php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9250 Nested Functions are BAD, they make for inefficient debugging
Submitted: 2001-02-14 04:10 UTC Modified: 2002-01-06 13:15 UTC
From: dsifry at linuxcare dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: Any
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: dsifry at linuxcare dot com
New email:
PHP Version: OS:

 

 [2001-02-14 04:10 UTC] dsifry at linuxcare dot com
If you have a missing close-bracket "}" somewhere in your code, the PHP parser tells you that the error is at the last line.  If you have a multi-hundred or thousand line file, this makes life a bitch.

Rasmus tells me that the reason for this behavior is because functions can be nested, which means that:

function a 
{
  function b
  {
  } 
}
is OK. This is a silly feature.  Why do you have it, for scoping reasons?  It means that you can't effectively tell where syntax errors occur.

Suggestion: Either make nested functions turned off by default but you can turn them on with a PHP global variable, like $PHP_BIZARRO_NESTED_FUNCTIONS = 1;

or

have the parser syntax set up so that it marks where a possible syntax error occurred (IOW it sees a possible nested function, but it could also be a syntax error), and if it reaches the end of the file with a missing "}" or two, that it displays the location where it parsed the nested function.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-06 13:15 UTC] jan@php.net
brackets are used for other controll structures as well, so disabling nested functions do not solve the problem. ->bogus
 [2010-03-09 02:59 UTC] benni at cipher dot is
nested functions make for grate walkers in recursive functions

BUT ! ONLY 
if the scope is limited with in the outer function  (witch it isn't)
AND can use same variables as outer function
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC