# Property setter and getter in PHP5

- Thread: https://externals.io/message/3515
- Original archive: https://news-web.php.net/php.internals/3515
- Started by Masoud on 2003-07-20T15:52:12+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #3515 — Masoud — 2003-07-20T15:52:12+00:00

URL: https://externals.io/message/3515#3515

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

---

## #3517 — John Lim — 2003-07-20T16:36:47+00:00

URL: https://externals.io/message/3515#3517 · In reply to: #3515

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...
> 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

---

## #3518 — Masoud — 2003-07-20T17:14:44+00:00

URL: https://externals.io/message/3515#3518 · In reply to: #3517

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...
> 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...
> > […]

---

## #3519 — Derick Rethans — 2003-07-20T17:19:43+00:00

URL: https://externals.io/message/3515#3519 · In reply to: #3518

Hi,



> 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/

---

## #3520 — Masoud — 2003-07-20T17:37:39+00:00

URL: https://externals.io/message/3515#3520 · In reply to: #3519

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...
> Hi,
>
> 
>
> > […]
>
> 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/

---

## #3540 — Matthias Blaser — 2003-07-21T10:50:35+00:00

URL: https://externals.io/message/3515#3540

> 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
