PHP 4.0 Bug #5157: Include function not acting as described in documentation
| From: | jordan at eblox dot com | Date: | Tue, 20 Jun 2000 19:08:01 +0000 |
| Subject: | PHP 4.0 Bug #5157: Include function not acting as described in documentation | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-21873@lists.php.net to get a copy of this message | ||
From: jordan@eblox.com
Operating system: Linux 2.2.14
PHP version: 4.0 Latest CVS (20/06/2000)
PHP Bug Type: Misbehaving function
Bug description: Include function not acting as described in documentation
the fix for bug #5152 was to change the Include() statement on page.php to Require() (also said to
use start_session(), but that had no effect, and is implicitly called by session_register() if no
session exists yet according to the php docs). Code listed below:
------------classdec.php-------------
<?
// class declaration
class TestClass {
var $a;
function heh($str) {
echo $str . "<br>";
}
}
?>
-----------index.php-----------------
<?
session_register("sessionvar");
Include("classdec.php");
// creating an instance of a class to pass as a session var to page.php
$sessionvar = new TestClass;
$sessionvar->a = "someval";
echo "<a href=page.php>link</a>";
?>
----------page.php-------------------<?
session_register("sessionvar");
// fix was to change this from Include()
Require("classdec.php");
$anothervar = new TestClass;
// I can use the variables of this instance that was created on index.php and put in a session
echo $sessionvar->a . "<br>";
// I can call this function on another instance of the same class that I created on this page
$anothervar->heh("this is output from the same function that generates an error on the next
line");
// .....crash telling me it's an undefined function.
$sessionvar->heh("rhewswh");
?>
===========================================
acording to the documentation in this particular example, the include function and require function
should not affect results in the manner that is shown above. Include() if only differnt from
Require if you place it in a for loop or similar structure that will cause it be parsed multiple
times. In this sistuation, there is no such loop, etc.
This may alternativly be listed as a documentation problem. If there is a good reason for the
current behavior of the Include() function, it is not described in the docs.
any comments would be appreciated.