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
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: elf@php.net
New email:
PHP Version: OS:

 

 [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: Tue Apr 16 21:01:28 2024 UTC