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] SOLVED: Global class instances mysteriously set to NULL

2005-01-10 Thread James \(IFMS\)
I *really* appreciate everybody's previous input. I may be a highly 
experienced programmer, but am relatively new to PHP.

OK, I figured out what was going on. Google enough and read enough and 
the light goes on finally.

The problem was not the require_once but a scoping problem. 
Specifically, I was calling require_once /from within a function/.

Bad! Bad! Bad!
The included source file was also including other files... thus the 
global class instance was just fine... it was simply hidden due to 
scoping rules.

Yikes! I was really pulling my hair out when entire global functions 
were disappearing due to the screwed up scope.

I finally figured out the problem in the User Contributed Notes 
section of the PHP manual (http://www.php.net/language.variables.scope).

THANK YOU again...
--
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


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

2005-01-09 Thread James \(IFMS\)
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, 
I didn't think about this.
I did follow up on your suggestion to no avail, then made *really* sure 
there is only *one* file by running updatedb and locate 
uAuthenticate as root.

--
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


[PHP] PHP form POST question

2005-01-09 Thread James \(IFMS\)
I just narrowed something down about forms and POST and would like 
education. In the following scenarios, all work except #4. $_POST is 
null. Why is that?

Setup:
1) Running on localhost
2) /foo/index.php has the following:
   ? var_dump($_POST); var_dump($_GET); ?
3) /index.php contends vary per scenario (below)
Running RHEL 3, all updates (PHP 4.3.2).
SCENARIO 1:
/index.php contains the following:
form method=get action=/foo/index.php
input name=foobutton type=submit
/form
In this case in /foo/index.php $_GET has the right value, i.e.
array('foobutton' = '');
SCENARIO 2:
/index.php contains the following:
form method=get action=/foo
input name=foobutton type=submit
/form
In this case in /foo/index.php $_GET has the right value, i.e.
array('foobutton' = '');
SCENARIO 3:
/index.php contains the following:
form method=post action=/foo/index.php
input name=foobutton type=submit
/form
In this case in /foo/index.php $_POST has the right value, i.e.
array('foobutton' = '');
SCENARIO 4:
/index.php contains the following:
form method=post action=/foo
input name=foobutton type=submit
/form
In this case in /foo/index.php $_POST is NULL.
HUH? Why is $_POST empty? Is Apache doing something to kill the form's 
post information when it has to resolve /foo to /foo/index.php?

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


Re: [PHP] PHP form POST question

2005-01-09 Thread James \(IFMS\)
When you access /foo, the server will redirect the client to /foo/ 
(because it is a directory). At the redirected page, the post data will 
not be sent again by the browser thus there are no _POST values.

Try using action=/foo/. That may work.
Yes, /foo/ does work.
The explanation makes sense.
Bugger! All that time spent banging my head against the wall. :-)
Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php