php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54945 Function declarations inside if/else statements don't work correctly
Submitted: 2011-05-28 12:38 UTC Modified: 2011-05-29 14:36 UTC
Votes:8
Avg. Score:3.8 ± 1.4
Reproduced:6 of 8 (75.0%)
Same Version:5 (83.3%)
Same OS:5 (83.3%)
From: charlie at charliesomerville dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS:
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: charlie at charliesomerville dot com
New email:
PHP Version: OS:

 

 [2011-05-28 12:38 UTC] charlie at charliesomerville dot com
Description:
------------
When declaring a function inside an if/else statement, the latter declaration is 
honoured regardless of which branch the if/else statement took.

Test script:
---------------
<?php

if(true)
{
    function foo()
    {
        echo "first foo.";
    }
}
else
{
    function foo()
    {
        echo "second foo.";
    }
}

foo();

Expected result:
----------------
first foo.

OR:

Syntax Error: Cannot declare function inside conditional statement

Actual result:
--------------
second foo.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-29 14:36 UTC] bjori@php.net
-Status: Open +Status: Bogus
 [2011-05-29 14:36 UTC] bjori@php.net
Disable the zend extensions you are using and try again.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 04:01:38 2025 UTC