php3-list | 2000051
Date: 05/08/00
- Next message: Maarten Stolte: "[PHP3] prepend and include set per virtual hosts?"
- Previous message: Saurabh Gupta: "Re: [PHP3] XML functions"
- In reply to: Rajani Iyer: "[PHP3] encapsulation in php..."
- Next in thread: Richard Lynch: "Re: [PHP3] encapsulation in php..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Dunno if you didn't get Manuel's earlier answer but it explains this pretty
well so here it is again:
<QUOTE>
This subject has been discussed before not very long time ago. PHP
supports encapsulation with its classes. What it doesn't support is data
(variable or function) hiding.
Data hiding serves no pratical purpose other than eventually preventing
foreign code to access private object data. Since PHP is an interpreted
language, an attempt to access protected private data would result on a
runtime error/failure. Data hiding is more useful for compiled languages
as they trap access violations at compile time, ie, before shipping the
software.
Anyway, I don't agree that the lack of data hiding renders PHP objects
useless. Data hiding is not even an object oriented characteristic, but
rather a feature of some object oriented languages.
Regards,
Manuel Lemos
</QUOTE>
So there you have it, 'private' variables don't exist in PHP. If you need
them so badly learn Java :)
I got an idea...
Why not prefix variables you want to be 'private' with say '_priv_' (eg
$_priv_foo) and set up get/set etc methods as you would in Java, then insist
that if any of your programmers use a $_priv_ variable in thier code they
start work at 8am in a suit&tie for a month, that should have the same
effect :)
Adam Robertson
==============
Web Application Developer
http://www.elitemedia.co.uk
>-----Original Message-----
>From: Rajani Iyer [mailto:rajani_21 <email protected>]
>Sent: 08 May 2000 17:38
>To: php3 <email protected>
>Subject: [PHP3] encapsulation in php...
>
>
>hi Michael,
>
>I'll look into the perl book recommended by you. In
>fact what you've written is exactly what i'm looking
>for in php. To be more specific let's take an example:
><?
>class Cart
>{
> private :
> var $owner;
> function set_owner(name){
> $this->owner = name;
> }
>
>}
>
>My_cart = new Cart
>Mycart->set_owner("Rajani");
>
>/* A statement like this should report an error */
>Mycart->owner = "Rajani"
>
>?>
>
>Only the class functions should be allowed to
>manipulate the values of the variables.
>
>But i tried declaring the scope of the variable as
>private in php as above. But gives me error.
>
>I want a soln for this badly. pl help...
>
>--Rajani
>
>
>
>__________________________________________________
>Do You Yahoo!?
>Send instant messages & get email alerts with Yahoo! Messenger.
>http://im.yahoo.com/
>
>--
>PHP 3 Mailing List <http://www.php.net/>
>To unsubscribe, send an empty message to php3-unsubscribe <email protected>
>To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
>To search the mailing list archive, go to:
>http://www.php.net/mailsearch.php3
>To contact the list
>administrators, e-mail: php-list-admin <email protected>
>
>
-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Maarten Stolte: "[PHP3] prepend and include set per virtual hosts?"
- Previous message: Saurabh Gupta: "Re: [PHP3] XML functions"
- In reply to: Rajani Iyer: "[PHP3] encapsulation in php..."
- Next in thread: Richard Lynch: "Re: [PHP3] encapsulation in php..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

