php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13616 Compiler complains about function declaration after return is called
Submitted: 2001-10-09 13:09 UTC Modified: 2002-12-06 19:55 UTC
From: brianm at dealnews dot com Assigned: ssb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0CVS-2001-10-09 OS: Linux
Private report: No CVE-ID: None
 [2001-10-09 13:09 UTC] brianm at dealnews dot com
We have been using code like this for a long time:

test.php:
<?php
  include "test2.php";
  include "test3.php";

  foo();
  bar();
?>

test2.php:
<?php
  if(defined("_TEST2")) return;
  define("_TEST2", true);

  function foo(){
    echo "foo\n";
  }
?>

test3.php
<?php
  if(defined("_TEST3")) return;
  define("_TEST3", true);

  include "test2.php";
  function bar(){
    echo "bar\n";
  }
?>


With 4.0.6 we get:
-------------------
$ php test.php
X-Powered-By: PHP/4.0.6RC4
Content-type: text/html

foo
bar

With current dev we get:
------------------------
$ ./php test.php   
X-Powered-By: PHP/4.0.8-dev
Content-type: text/html

Fatal error: Cannot redeclare foo() (previously declared in /home/brianm/test2.php:6) in /home/brianm/test2.php on line 7

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-09 13:57 UTC] sander@php.net
Reclassified.
 [2001-10-10 02:31 UTC] derick@php.net
Marking as fix before release
 [2001-10-10 14:40 UTC] sander@php.net
Reproduced with latest dev from php4win.com (04-Oct-2001).
 [2001-10-11 20:20 UTC] ssb@php.net
Example can be reduced to:

test.php:
<?php
function foo() {}
include "test2.php";
?>

test2.php:
<?php
return;
function foo() {}
?>

 [2001-10-17 11:53 UTC] ssb@php.net
This turns out to be due to another bug fix (9884), and will probably
end up being documented as a compatibility breaker in 4.1.0. 
I recommend that you use include_once instead.

 [2001-10-17 17:34 UTC] brianlmoon@php.net
I have a zend_compile.c that will allow the same function from the same file too pass through with a NOTICE rather than a fatal ERROR.  Is this of interest to anyone?  It is a good interim solution I think.
 [2001-10-17 17:35 UTC] brianlmoon@php.net
I worded that poorly, It in fact does not do the zend_hash_add the second time, thus keeping a function from ever being added twice.
 [2002-12-06 19:55 UTC] sniper@php.net
Seems to be fixed in PHP 4.3.0-dev.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 17:01:33 2024 UTC