Re: [PHP] Global class instances mysteriously set to NULL

2005-01-10 Thread Richard Lynch
James \(IFMS\) 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. :-)

Most likely, somewhere along the way, one of your files is triggering some
condition which 'unsets' your variable.

It's also possible that you've got your require's out of sequence
somewhere in there.

Personally, I always structure my code so that there is only one place
where any given file will be require'd so I don't need require_once.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Global class instances mysteriously set to NULL

2005-01-10 Thread James \(IFMS\)
Most likely, somewhere along the way, one of your files is triggering some
condition which 'unsets' your variable.
That's what it looks like. I can't find anything in the documentation or 
on the 'Net that describes such a condition. That's why I originally 
posted the question.

Personally, I always structure my code so that there is only one place
where any given file will be require'd so I don't need require_once.
Out of long habit from other languages I'm used to simply listing all 
dependencies at the begining and letting the compiler sort things out.

I want the failure that require provides, but don't want to have to 
map out all these class file dependencies so laziness demanded 
require_once. :-)

Still learning the quirks of PHP. Every language has them.
(Now C++... yikes! That's a very quirky language. Once you learn where 
the Don't Do That rule applies, it's fine. I'm NOT trying to start any 
stupid language flame fest. Just saying that language was the one that 
gave me the most heartburn to date.)

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


[PHP] Global class instances mysteriously set to NULL

2005-01-09 Thread James \(IFMS\)
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. :-)
Thanks,
James
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Global class instances mysteriously set to NULL

2005-01-09 Thread Jason Wong
On Monday 10 January 2005 03:34, James (IFMS) wrote:

 I'm currently trying to determine rhyme or reason for the problem, but
 haven't found any pattern. 

OK, but ...

 It comes and goes depending on which file 
 first calls require_once and the order, 

... doesn't this contradict the above?

Is there or is there not a pattern? Can you make it fail/work consistently by 
changing the order of the require_once()?

 but makes no sense. 

As long as you've got something that is consistent and reproducible then 
eventually some sense can be made out of it. But if you're saying that 
running the same code without changes repeatedly will give random results 
then *that* doesn't make sense.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
New Year Resolution: Ignore top posted posts

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



Re: [PHP] Global class instances mysteriously set to NULL

2005-01-09 Thread James \(IFMS\)
As long as you've got something that is consistent and reproducible then 
eventually some sense can be made out of it. But if you're saying that 
running the same code without changes repeatedly will give random results 
then *that* doesn't make sense.
Very true. I wasn't too clear.
Switching around (and removing) require_once in different source files 
does cause different results *consistently*.

If I have require_once 'uAuthenticate.php' in one source file it 
causes the problem, but if remove it, or add/remove it from another 
source file the problem goes away.

What I mean by no rhyme or reason is that even though I get consistent 
results of problem/no problem, I see no pattern to what causes the 
problem and what does not. It's really screwy, at least from my 
understanding of how require_once should work. (It's possible of course 
that I simply may be misinterpreting the documentation.)

While I would like to understand the problem so that I know don't do 
that you fool, I also am short on time.

I was able to find a work-around thus:
1) In the source file that's the #1 problem child I changed
require_once 'uAuthenticate.php';
to
require 'uAuthenticate.php';
2) in uAuthenticate.php I changed
$Auth = new TAuthenticate;
to
if(!isset($Auth))
  $Auth = new TAuthenticate;
This doesn't seem to nuke the global $Auth.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php