Re: prototypes for getters and setters.

From: Date: Wed, 13 Nov 2002 02:09:01 +0000
Subject: Re: prototypes for getters and setters.
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-90924@lists.php.net to get a copy of this message
Very interesting and another syntax suggestion: var $variable ( getter, setter[, default] ); i havent't took a look in ther parser scripts yet but this seems easier. Anyway the problem is that you cannot have a setter without a getter. What about var $variable ( [get=getter] [set=setter] [default=value] ); or var $variable [= value] ( [get=getter] [set=setter] ); optionally we could have array support like delphi var $variable[] ( [get=getter] [set=setter] ); where gettter/setter are a functions whos first parameter is the index value function getVariable(index) value function setVariable(index, value); marcus At 02:31 13.11.2002, Alan Knowles wrote:
Thanks to a little chat (and a few beers) with Zak at the conference, I got wondering if this syntax would be a sensible addition... The principle is to enable rapid prototyping of getter and setter methods..... class something { var getBanana setBanana $banana = 12; var getOrange $orange =1; function setOrange($value) {
       if ($value == $this->banana) {
           echo "mmh banana's and oranges are the same";
       }
} } $t = new something; echo $t->getBanana(); echo $t->setBanana(3); echo $t->setOrange(3); syntax: var [getter method] [setter method] $variable .....; or any other ideas var (getBanana, setBanana) $banana function var getBanana, setBanana for $banana = '12'; // nice bit of token recycling..... var use getBanana and setBanana for $banana = '12'; from a quick play with zend_language_parser.y the additionall code to class_variable_decleration: would look a bit like this...
|     is_reference T_STRING T_VARIABLE  '=' static_scalar    {
               znode tmp;
               znode tmpthis;
               znode tmpfinalval;
               zend_copy_value(tmpthis, 'this', 5);
               tmpthis->type = IS_STRING;
               zend_do_declare_property(&$3, &$6 TSRMLS_CC);
               function.u.opline_num = CG(zend_lineno);
               zend_do_begin_function_declaration(&function, &$3, 1, $2.op_type TSRMLS_CC); }
               # get the 'this' part..
               zend_do_fetch_globals(&tmpthis TSRMLS_CC);
               zend_do_begin_variable_parse(TSRMLS_C);
               fetch_simple_variable(&tmp, &tmpthis, 1 TSRMLS_CC);
               zend_do_fetch_property(&tmpfinalval, &tmp, &$6 TSRMLS_CC);}
                zend_do_return(&tmpfinalval, 1 TSRMLS_CC);
               zend_do_end_function_declaration(&$1 TSRMLS_CC);
       }
Anyway before I get carried away and actually test this :) - anybody got any thoughts..... Regards Alan -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.dev (#90924) next »