php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9064 Functions inside functions cause errors if the outer function is called twice.
Submitted: 2001-02-01 22:18 UTC Modified: 2001-02-02 04:14 UTC
From: chriskl at familyhealth dot com dot au Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: FreeBSD 4.2-STABLE
Private report: No CVE-ID: None
 [2001-02-01 22:18 UTC] chriskl at familyhealth dot com dot au
This script fails with:

<b>Fatal error</b>:  Cannot redeclare test2() in <b>-</b> on line <b>4</b><br>

<?php

function test() {
	function test2() {
		echo "hi";
	}

	test2();
}

test();
test();
test();

?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-02 04:14 UTC] hholzgra@php.net
php has no "nested function" feature like you'll find in PASCAL 
or in gcc if you enable the feature

what happens here is that test2 is registered on execution of
test in the global namespace, and when you call test a second time
it cannot register test2 again

(the engine shouldn't  accept nested functions at all i think)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 13:01:30 2024 UTC