Re: Global class instances mysteriously set to NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



James wrote:
I'm struggling to narrow this down, and am chasing my tail to figure this out. I apologise for the imprecise nature.

PHP: 4.3.2 (latest RHEL 3 version; php-4.3.2-19.ent.src.rpm)
OS: Linux kernel 2.4.21-15.0.3.EL
Distro: RHEL 3, all updates

I have an app that defines two global class instances, one for the database connection, the other for handling user authentication. The first is instantiated in uDatabase.php the other in uAuthenticate.php.

In building a page, there are several files that call require_once with one or the other file, e.g.

require_once 'uAuthenticate.php';

Which creates an a global instance of a class defined in another file, performs some checks, &c.

I'm using require_once with the understanding that once this file has been included, that any subsequent require_once call to the same file will be ignored.

My problem is that it appreas that in some cases require_once destroys the instance, i.e. var_dump($Auth); or var_dump($Database) displays NULL.

I'm currently trying to determine rhyme or reason for the problem, but haven't found any pattern. It comes and goes depending on which file first calls require_once and the order, but makes no sense.

ANY ideas apreciated. :-)

Since you are using relative includes (require_once 'uAuthenticate.php';)

You must make sure that there is only *1* uAuthenticate.php file being included. To verify that this is the case, try this code at the end of the main file:

<?php
var_dump(get_included_files());
?>

If you switch the ordering of inclusion and get a different listing, there's your answer.

Greg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux