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 this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC