Re: Scope of variable in Class

From: Date: Tue, 07 Nov 2000 04:05:19 +0000
Subject: Re: Scope of variable in Class
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-24048@lists.php.net to get a copy of this message
Thank you for the quick respond. Is there any suggestion how can I effectively "shoot" a user that accesing my prefix 'private' variables other than doing code review? I'm actually developing an API/wrapper using classes. The users that are using these classes should not be allowed to access some of the 'private' variable (ie. for security reason) from their program. Unfortunatelly, until now I allow them to look at the API. Reuben D. B At 07:37 PM 11/6/00 -0800, Lars Torben Wilson wrote:
Reuben D Budiardja writes: Suppose I have a class: class Cart {
       var $items;
       function add_item ($num) {
         $this->items = $num;
         }
} I can access (ie. print) $items by doing: $myCart = new Cart; echo $myCart->items; My question: is there any way so that someone can NOT access $items? in order words, make $items a PRIVATE variable for the class only? Thanks Reuben D. Budiardja No. You could always just prefix 'private' variables with an underscore or something and tell users that anyone using '->_' unless it immediately follows a '$this' will be shot, but that's about it. -- +----------------------------------------------------------------+
|Torben Wilson <torben@php.net>                     Netmill iTech|
|http://www.coastnet.com/~torben            http://www.netmill.fi|
|Ph: 1 250 383-9735                             torben@netmill.fi|
+----------------------------------------------------------------+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.general (#24048) next »