From:             csaba at alum dot mit dot edu
Operating system: 
PHP version:      5.1.1
PHP Bug Type:     Scripting Engine problem
Bug description:  auto_prepend_file neither prepends nor includes

Description:
------------
auto_prepend_file in the php.ini file neither acts as if it prepends the
designated file nor as if it were included (as stated at
http://hu.php.net/manual/en/ini.core.php#ini.auto-prepend-file).

Specifically, if this were the case, then functions defined in the main
script would take precedence over functions defined in the
auto_prepend_file, but they do not.

Use case: It seems reasonable to define a standard library of all
functions available to all scripts under a php installation (through the
auto_prepend_file php.ini setting).  It also makes sense for select
scripts to be able to override these functions.  In a single .php file
(with no auto_prepend_file present), this would be accomplished as follows
with Script1:

<?php
if (!function_exists('showLine')) {
function showLine($letter) { print "First $letter.\n"; } }
showLine("B");
function showLine($letter) { print "Second $letter.\n"; }
?>

This produces no error, and an output of: Second B.  If the last line is
commented out, you would instead get: First B.



Moving the first two lines to includeMe.php:
<?php
if (!function_exists('showLine')) {
function showLine($letter) { print "First $letter.\n"; } }
?>

and invoking the following script2 leads to the same result:
<?php
include('includeMe.php');
showLine("B");
function showLine($letter) { print "Second $letter.\n"; }
?>


However, if php.ini's auto_prepend_file now points to includeMe.php and
the include statement is removed from script2 to yield script3, script3
will error with a duplicate function definition, which is what I am
reporting as improper behaviour.  Script3:
<?php
showLine("B");
function showLine($letter) { print "Second $letter.\n"; }
?>


Thanks,
Csaba Gabor from Vienna

Expected result:
----------------
My expectation for what the auto_prepend_file does is that it either
prepends the designated file to the main script, or treats it as having
been named by an include/require function as the 1st line of the script
(the difference is effectively whether the function definitions in the
auto_prepend_file are seen before the main script's function definitions
or not).

To be specific:  Remove, the first statement from the doc and have only
(with code to match): Specifies the name of the file to be parsed as if it
were called via an include construct at the very beginning of the main
script (so include_path is used).

Actual result:
--------------
The documentation at the page above claims two contradictory things:  It
says that auto_prepend_file is parsed before the main file, and it says
that the file is included as if it were called with the include()
function.

The current situation is that the auto_prepend_file is parsed separately
(before) the main script file (as opposed to prepended or included), but
the file name is placed onto the include file list (so that it can no
longer be include_once'd - see also: http://bugs.php.net/bug.php?id=32924)

-- 
Edit bug report at http://bugs.php.net/?id=35811&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=35811&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=35811&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=35811&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=35811&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=35811&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=35811&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=35811&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=35811&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=35811&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=35811&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=35811&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=35811&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=35811&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=35811&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=35811&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=35811&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=35811&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=35811&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=35811&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=35811&r=mysqlcfg

Reply via email to