php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15105 Declaring a function twice
Submitted: 2002-01-18 14:14 UTC Modified: 2002-01-18 14:26 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: tapken at engter dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.1.1 OS: Linux
Private report: No CVE-ID: None
 [2002-01-18 14:14 UTC] tapken at engter dot de
Don't know if this is a bug or a feature...

-foo.php----------------------------------------
<?php
if (!$bar) {
    $bar = true;
    include(__FILE__);
    exit;
}
function foo() {
    return true;
}
?>
-/foo.php----------------------------------------

This is a VERY simplified version of a script i'm working on. foo() should only be declared once but PHP says:
<b>Fatal error</b>:  Cannot redeclare foo() in <b>/home/roland/tmp/foo.php</b> on line <b>7</b><br>

ok, i know how a can work around this problem... in this case just put the rest of the file into the else-statement. But nevertheless it is an interesting phenomen...

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-18 14:26 UTC] sander@php.net
It's a dupe... can't find the bug anymore, but it is a dupe.
 [2002-01-18 14:26 UTC] hholzgra@php.net
"should only be declared once" is true,
and on the second try it gives an error
as it *can* only be declared once instead
of just silently ignoring it
(there's no practical way for the parser
 to find out that it is *exactly* the same
 definition)

hint: http://php.net/function_exists
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 07 18:01:28 2024 UTC