PHP Class Question

From: Date: Mon, 01 Oct 2001 15:17:50 +0000
Subject: PHP Class Question
Groups: php.lang 
Request: Send a blank email to php-lang+get-216@lists.php.net to get a copy of this message
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 - dsn@gatech.edu - System Support Specialist I Office of Information Technology - Georgia Institute of Technology

« previous php.lang (#216) next »