php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #33293 a problem in a sample
Submitted: 2005-06-10 04:31 UTC Modified: 2005-06-10 09:14 UTC
From: elf@php.net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 + 25 = ?
Subscribe to this entry?

 
 [2005-06-10 04:31 UTC] elf@php.net
Description:
------------
http://www.php.net/manual/en/language.functions.php#AEN5142

a problem exists in the sample of a manual.
this problem is not checking exist of bar.

The right example:
<?php
function foo() 
{
  if ( !function_exists( "bar")) <== add
  {                              <== add
    function bar() 
    {
     echo "I don't exist until foo() is called.\n";
    }
  }                              <== add
}
?> 


Reproduce code:
---------------
<?php

error_reporting(E_ALL);
ini_set( "display_errors", "on");

function foo()
{
  function bar()
  {
   echo "I don't exist until foo() is called.\n";
  }
}
foo();
bar();
foo();  //  Fatal error: Cannot redeclare bar()

?>


Expected result:
----------------
Fatal error: Cannot redeclare bar() (previously declared in /path/for/script/foo.php:10) in /path/for/script/foo.php on line 8


Actual result:
--------------
I don't exist until foo() is called.
I don't exist until foo() is called.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-10 09:14 UTC] vrana@php.net
Think about foo() as a function defining new function. You can't call foo() several times the same as you can't define a function several times.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC