[phplib] Object scoping and form variables in PHP4 From: Chris Mayes (cmayes3 <email protected>)
Date: 08/14/00

Hello, everyone. This is a more general PHP question, but I don't
really know where else to ask since the php3 list seems to be dead
(does anyone have a suggestion?).

So, the situation is that I am totally obsessed with object orientation
and have wrapped all of my page generation code into an object.
Everything had been working quite smoothly (I've even made template and
db objects properties of the object), but I've just recently discovered
that form variables are not available to the object scope. The
variables are set in the calling page and are even within the scope for
"required" pages called within the object (I'm "ob"ing the output from
a page that runs Manuel Lemos's form class to stuff into the template
structure), but they aren't available to native methods of the class.

Is there a non-hackish way to import form variables into the object's
scope? Should I send the HTTP_GET/POST_VARS into the object and step
through the hashes (this'd require a property definition for each
variable, but I suppose that's the way objects should be done; it would
just make for a rather tall class definition), or is there a way to
pass the entire local symbol table to the object (which would save me
some logic within each of the objects since PHPLIB would have already
filled the $<name> with each form variable)? I'd also like to avoid
making the whole thing "global" since it's been beaten into my head
since my first programming class that global variables are A Bad Thing.

As you might have guessed, I haven't done a ton of object-oriented
programming, though I do find it to be a lot of fun (generally). This
question may set some purists' teeth on edge, but why doesn't PHP4
allow an object created and called within a page's scope to access
variables from that page's symbol table? From what I've seen,
variables local to the object would either be called with the $this->
syntax or would be defined locally within the scope of a method. I
have more experience with Perl (which tends to be very strict with a
variable's scope, especially when one uses the 'strict' pragma), and
variable declaration and scoping seems looser in PHP. Why have we
drawn the line at an object's symbol table?

Again, all of the above is most likely off-topic for this list, so if
someone could tell me which list is more appropriate for general PHP4
questions, please let me know. Also, a pointer to a searchable archive
of said list would be a big bonus. I haven't seen anything show up on
Geocrawler yet...

Thanks,

-Chris

__________________________________________________
Do You Yahoo!?
Yahoo! Mail – Free email you can access from anywhere!
http://mail.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>