php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41383 Function in 'required' File doesn't Appear to Exist
Submitted: 2007-05-13 10:38 UTC Modified: 2007-05-13 18:37 UTC
From: chris at dented-planet dot net Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.2 OS: Mac OS X
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chris at dented-planet dot net
New email:
PHP Version: OS:

 

 [2007-05-13 10:38 UTC] chris at dented-planet dot net
Description:
------------
The documentation on functions (http://www.php.net/manual/en/language.functions.php) says:
"In PHP 3, functions must be defined before they are referenced. No such requirement exists since PHP 4. Except when a function is conditionally defined..."

I don't understand why the following code (in three different files BTW) doesn't work as expected. It doesn't seem to be conditionally defined.

Tested with PHP 4.4.4-CLI, PHP 5.2.1, PHP 5.2.2.

I am openminded that this may not be a bug but I can't seem to find an explanation.



Reproduce code:
---------------
FILE a.php:

<?php

error_reporting(E_ALL | E_NOTICE);

echo "FILE 'a.php'\n";

if (function_exists('test')) {
    echo test();
}
else {
    echo "function 'test()' doesn't exist!\n";
}

require 'b.php';

?>

------

FILE b.php

<?php

echo "FILE 'b.php'\n";

require 'c.php';

?>

------

FILE c.php

<?php

echo "FILE 'c.php'\n";

function test()
{
    return "function test() was called!\n";

}

?>


Expected result:
----------------
SIGNIFICANT expected result: 'function test() was called!' is echoed. Other output is for debugging.



Actual result:
--------------
Actual result: 'function 'test()' doesn't exist!' is echoed.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-13 16:46 UTC] chris at dented-planet dot net
Okay, it was explained to me why this doesn't work. That's why I said that it might not be a bug.

It isn't a bug, indeed. The only thing that is buggy is my ability to read the documentaion more thoroughly.

Case Closed
 [2007-05-13 18:37 UTC] sniper@php.net
PEBCAK :D
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 30 08:00:03 2025 UTC