Property setter and getter in PHP5

php.internals

Masoud

23 years ago
It's just a suggestion to have a syntax like this in PHP5! A property is similar to a field (a member variable), with the exception that there is a getter and a setter method, as follows : public class Car { private string make; public string Make { get { return make; } set { make = value; } } } Car c = new Car( ); c.Make = "Acura"; // use setter String s = c.Make; // use getter above example is a simple C# example in NET Framework Essentials. Masoud

(Marcus Börger)

23 years ago
Hello Masoud, Sunday, July 20, 2003, 5:52:12 PM, you wrote: M> It's just a suggestion to have a syntax like this in PHP5! M> A property is similar to a field (a member variable), with the exception M> that there is a getter and a setter M> method, as follows : M> public class Car M> { M> private string make; M> public string Make M> { M> get { return make; } M> set { make = value; } M> } M> } M> Car c = new Car( ); M> c.Make = "Acura"; // use setter M> String s = c.Make; // use getter M> above example is a simple C# example in NET Framework Essentials. Other languages support this too. Have a look a __get and __set.
-- Best regards, Marcus mailto:helly@php.net

Sebastian Bergmann

23 years ago
Marcus B?rger wrote:
> Have a look a __get and __set.
But those only work on undefined properties.
-- Sebastian Bergmann http://sebastian-bergmann.de/ http://phpOpenTracker.de/ Das Buch zu PHP 5: http://professionelle-softwareentwicklung-mit-php5.de/

(Marcus Börger)

23 years ago
Hello Sebastian, Monday, July 21, 2003, 8:11:30 AM, you wrote: SB> Marcus Börger wrote:
>> Have a look a __get and __set.
SB> But those only work on undefined properties. Sure i know that and i didn't state different. SB> Das Buch zu PHP 5: http://professionelle-softwareentwicklung-mit-php5.de/ AND PLEASE don't tell us about your book here. It's like saying you all must buy my book. But most ppl here don't speak german :-)
-- Best regards, Marcus mailto:helly@php.net

Peter Neuman

23 years ago
Hello, "Marcus Börger" <marcus.boerger@t-online.de>
> AND PLEASE don't tell us about your book here. It's like saying you all
must
> buy my book. But most ppl here don't speak german :-)
Dann müssen Sie es eben lernen, Wir Deutschen müssen auch Englisch lernen, und wer das nicht will hat pech... Then you must learn it evenly, we Germans must also English learn, and who does not want that has pitch... HTH Peter Neuman

Matthias Blaser

23 years ago
On Monday 21 July 2003 12:23, Peter Neuman wrote:
> Then you must learn it evenly, we Germans must also English learn, and > who does not want that has pitch...
... and why didn't you learn it and translate your german text with altavista?? ;-) SCNR, Matthias

(Marcus Börger)

23 years ago
Hello Peter, Monday, July 21, 2003, 12:23:35 PM, you wrote: PN> Hello, PN> "Marcus Börger" <marcus.boerger@t-online.de>
>> AND PLEASE don't tell us about your book here. It's like saying you all
PN> must
>> buy my book. But most ppl here don't speak german :-)
PN> Dann müssen Sie es eben lernen, Wir Deutschen müssen auch Englisch lernen, PN> und wer das nicht will hat pech... PN> Then you must learn it evenly, we Germans must also English learn, and PN> who does not want that has pitch... The point is that many subscribers on this list write books and most of them don't spam the list but make a nice announcement when the book is ready to buy. I mean we all know already that sebastian is writing a book. He told us already a million times :-)
-- Best regards, Marcus mailto:helly@php.net

Andi Gutmans

23 years ago
I am with Sebastian on this one (as long as it stays in the signature and not the subject ;) Andi

John Lim

23 years ago
Hi Masoud, It's already available. See http://www.phppatterns.com/index.php/article/articleview/28/1/2/ "Masoud" <masoud@iranphp.net> wrote in message news:20030720155214.18238.qmail@pb1.pair.com...

Masoud

23 years ago
Hi John I knew __get and __set available, but i want to told C# like syntax is a nice and clear syntax if available in php5 , so we dont need to check property name and then set value . "John Lim" <jlim@natsoft.com.my> wrote in message news:20030720163649.50501.qmail@pb1.pair.com...

Derick Rethans

23 years ago
Hi, On Sun, 20 Jul 2003, Masoud wrote:
> I knew __get and __set available, but i want to told C# like syntax is a > nice and clear syntax if available in php5 , > so we dont need to check property name and then set value .
You can use C# for that ;) No really, I think the PHP 5 syntax is okay here, PHP is just not C#. regards, Derick
-- "Interpreting what the GPL actually means is a job best left to those that read the future by examining animal entrails." ------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ International PHP Magazine http://php-mag.net/ -------------------------------------------------------------------------

Masoud

23 years ago
Hi Derick which syntax is clear ? current syntax ? //--------------------------------------------------- class testClass { function __set($name,&$value) { switch ($name) { case 'propertyOne': { //do something $value='anything'; return true; break; } case 'propertyTwo': { //do something break; } } } } or c# like syntax ? //--------------------------------------------------------------- class testClass { var $propertyOne { get { //do something return $value; } set { //do something $propertyOne=$value; } } } It was just a suggestion to better (clear and bugfree) coding . Masoud "Derick Rethans" <derick@php.net> wrote in message news:Pine.LNX.4.53.0307201918460.6493@jdi.jdimedia.nl...