PHP Class Question
[email protected] ("Jeremiah Spradlin") Mon, 1 Oct 2001 11:17:50 -0400
| Newsgroups | php.lang |
|---|---|
| Message-ID | <[email protected]> |
I've been working on a large PHP project here at work, and I have a quick
class question regarding 'classes' in PHP, since what I am seeing in my code
tends to be opposite of what the PHP manual on the web page ( ie:
http://www.php.net) and a couple other books I've seen
say.
First, I'm an advanced user of C/C++ and Perl, and I've
done a good amount of PHP work already (I just haven't
used PHP with 'classes' yet .. ie: OO ).
According to the PHP manual, PHP classes are 'public' and any variable and
methods within these classes are 'public' as well. For example, if I had
the following variable $temp_var and the following function 'temp_func'
then I could access them the following way:
$class_object = new TempClass();
$class_object->temp_var = 3;
echo 'Temp Var = $class_object->temp_var';
$return = $class_object->temp_func();
echo 'Temp func return = $return';
Now, I can not get this behavior to work in any sort of way. I have,
however, figured out that the 'class variables' and 'class methods' are in
many ways 'private'. I can not access 'class variables' unless I 'global'
them IN the 'class functions' themselves. For example, the following code
fragment shows what I am doing to access the class variables within class
functions.
class TempClass
{
var $temp_var;
function TempFunc()
{
global $temp_var;
$temp_var = 3;
echo $temp_var;
}
}
I can not access a class variable unless its 'global'. My question is:
"Is the manual wrong, or has something in the PHP language changed?"
Thanks,
-
Jeremiah Spradlin - [email protected] - System Support Specialist I
Office of Information Technology - Georgia Institute of Technology