For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > June 2005 > #33293 [Opn->Bgs]: a problem in a sample









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #33293 [Opn->Bgs]: a problem in a sample
vrana@php.net

2005-06-10, 8:55 am

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/langua...ons.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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com