#33293 [Opn->Bgs]: a problem in a sample

From: Date: Fri, 10 Jun 2005 07:14:53 +0000
Subject: #33293 [Opn->Bgs]: a problem in a sample
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969368519@lists.php.net to get a copy of this message
 ID:               33293
 Updated by:       vrana@php.net
 Reported By:      elf@php.net
-Status:           Open
+Status:           Bogus
 Bug Type:         Documentation problem
 Operating System: any
 PHP Version:      Irrelevant
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2005-06-10 04:31:37] 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.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33293&edit=1


Thread (2 messages)

« previous php.doc (#969368519) next »