PHP :: Bug #54945 :: Function declarations inside if/else statements don't work correctly
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
 [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-2018 The PHP Group
All rights reserved.
Last updated: Tue Aug 14 08:01:25 2018 UTC