Bug #69921 [Nab]: function_exists returns true before function definition

From: Date: Wed, 24 Jun 2015 17:58:32 +0000
Subject: Bug #69921 [Nab]: function_exists returns true before function definition
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193854@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69921&edit=1

 ID:                 69921
 User updated by:    alan at aondra dot com
 Reported by:        alan at aondra dot com
 Summary:            function_exists returns true before function
                     definition
 Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Any
 PHP Version:        5.6.10
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

1. It should be documented on the function_exists page that it does not work as would be expected of
pretty much everything else.

2. Even if it is documented, its function still hinges on broken logic. Not that this is a first by
any means. See:
    i.imgur.com/pyDTn2i.jpg
    i.imgur.com/40VnUX1.png

Saying "because you didn't read an unlinked document (existence not hinted) in the manual,
and expect sane code, it's not a bug" doesn't mean it's not a bug. It's
still a bug.


Previous Comments:
------------------------------------------------------------------------
[2015-06-24 17:09:06] cmb@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

According to the documentation[1]:

| Functions need not be defined before they are referenced, [...]

function_exists() yields a result accoring to this, i.e. where
a function can be called, function_exists() returns true.

[1] <http://php.net/manual/en/functions.user-defined.php>

------------------------------------------------------------------------
[2015-06-24 15:10:45] alan at aondra dot com

.

------------------------------------------------------------------------
[2015-06-24 14:57:52] alan at aondra dot com

Gave a better summary

------------------------------------------------------------------------
[2015-06-24 14:56:19] alan at aondra dot com

Description:
------------
---
From manual page: http://www.php.net/function.function-exists
---

The function 'function_exists' does not execute in the order in which the code is
evaluated. Not only is this wrong, it allows for the possibility that code could be executed in the
incorrect scope.

I saw this note on the documentation:

"A function name may exist even if the function itself is unusable due to configuration or
compiling options (with the image functions being an example)."

I looked and found no such configuration or compiling option that would allow for this.

Test script:
---------------
<?php
    header('Content-Type: text/plain');

    $mystr = 'should not execute';

    if(function_exists('myfunc'))
        { myfunc($mystr); }

    $mystr = 'execute';

    function myfunc($str)
        { die($str); }

    myfunc($mystr);

Expected result:
----------------
execute

Actual result:
--------------
should not execute


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



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


Thread (5 messages)

« previous php.bugs (#193854) next »