php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #35811 auto_prepend_file neither prepends nor includes
Submitted: 2005-12-27 01:42 UTC Modified: 2006-01-03 18:30 UTC
From: csaba at alum dot mit dot edu Assigned: dmitry (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 5.1.1 OS:
Private report: No CVE-ID: None
 [2005-12-27 01:42 UTC] csaba at alum dot mit dot edu
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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-27 14:58 UTC] sniper@php.net
I don't understand a word of this report so I assume it's documentation issue. The ini option behaves just like it's meant to.
 [2005-12-27 23:20 UTC] csaba at alum dot mit dot edu
I start off with: The named auto_prepend_file should act as either a prepended file (that is, a section placed at the beginning of the main script) or as an include file (placed at the beginning of the main script).  If this assumption about the intent of the auto_prepend_file is incorrect, then sniper would be correct that there is merely a documentation issue.

In effect, the way a script is run is that first the main script file is parsed for syntax and (key point!) functions are defined, but the script is not yet interpreted.  AFTER the parsing/definition phase the script is interpreted (Script1 in the initial report demonstrates this). Therefore, if include('includeMe.php') is at the beginning (or anywhere else) of the main script, all the functions in the main script should be defined before the script of includeMe.php is interpreted (Script2 and includeMe.php demonstrate this).

That is to say: the consequence of my main assumption is that all functions in the main script should be defined before the auto_prepend_file script is interpreted.  However, this is not what happens with auto_prepend_file=c:\path\to\includeMe.php.  The script in includeMe.php is interpreted before the functions in the main script file are defined (as Script3 in the initial report demonstrates).  This contradics my initial assumption, which I feel indicates a php bug rather than an error in my assumption.  That is to say, the auto_prepend_file is not behaving as it is indended to, and I suggest this behaviour should be corrected rather than the documentation merely changed to reflect behaviour.  The use case in the initial report is intended to bolster this argument.

Csaba

Perhaps auto_prepend_file does behave as the developers meant it to, but then it doesn't seem consistent with the option name nor the spirit of the documentation.  If the initial creator of the option had intended it to behave as it is, would it not have made more sense to have picked a name along the lines of auto_start or auto_preload or auto_load, reflecting the intention more strongly?

  There's a documentation problem in any event, but shouldn't that wait till the true intention of the option has been decided?  Thus, I hope I'm not out of line in recategorizing this as a Scripting Engine problem.
 [2005-12-28 11:46 UTC] sniper@php.net
Dmitry, good luck trying to interpret whatever the problem is supposed to be. I still don't see any bug here..
 [2005-12-29 12:22 UTC] dmitry@php.net
ZE works as expected.
The file defined in "auto_prepend_path" parsed and executed before main file. This behavior is differ from include().

Seems this is a documentation problem.
 [2006-01-03 18:30 UTC] vrana@php.net
Imagine auto_prepend_file this way:

<?php
include "prepend_file.inc";
include "main_file.inc";
?>

This behaves the same way and produces the same error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC