Re: [PHP-DEV] prototypes for getters and setters.

2002-11-13 Thread Timm Friebe
On Wed, 2002-11-13 at 02:31, 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...
[...]
 syntax:
var [getter method] [setter method] $variable .;
+1

Plus, another syntax suggestion (coming in closer to Delphi):
  [type] $var read [getter] write [setter] [= default_value];
e.g.
  var $variable read getBanana write setBanana = 12;

Maybe even adding the default keyword:
  [type] $var read [getter] write [setter] default [= default_value];
e.g.
  var $variable read getBanana write setBanana default = 12;

and array offsets as suggested in another mail:
  [type] $var[[]] read [getter] write [setter] default [=
default_value];
e.g.
  var $variable[] read getBanana write setBanana default = array();

or alternatively
  [type] $var read[[]] [getter] write[[]] [setter] default [=
default_value];
e.g.
  var $variable read[] getBanana write[] setBanana default = array();


-
[type] is either var, public, private or protected
-

The default property is probably best explained in this example:

  class StringList {
public $strings[] read get write put default = array();

function get($index) {
  return $this-strings[$index];
}

function put($index, $value) {
  $this-strings[$index]= $value;
}
  }

  $s= new StringList();
  $s['hello']= 'world';

This would be equivalent to 

  $s-strings['hello']= 'world';

and call

  $s-put('hello', 'world');

although the default property is probably quite a bitch to handle
parser-wise.

-- 
Timm
Any sufficiently advanced bug is indistinguishable from a feature


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-13 Thread Derick Rethans
On 13 Nov 2002, Timm Friebe wrote:

 On Wed, 2002-11-13 at 02:31, 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...
 [...]
  syntax:
 var [getter method] [setter method] $variable .;
 +1
 
 Plus, another syntax suggestion (coming in closer to Delphi):

I'm -1 on these klugdes, as the overload functionality works fine IMO.

Derick

-- 

---
 Derick Rethans   http://derickrethans.nl/ 
 JDI Media Solutions
--[ if you hold a unix shell to your ear, do you hear the c? ]-


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-13 Thread Andrei Zmievski
On Wed, 13 Nov 2002, John Coggeshall wrote:
 
 I understand what your saying, however I guess I see the tradeoff of
 creating a new reserved word to a (IMHO of course) kinda messy new
 syntax a good one. 
 
 Besides, having an absolute standard for get/set would be benefital to
 all developers.. Knowing that setting $foo is always setfoo() (or
 set_foo(), makes no difference) would be nice. 

We do have an absolute standard: __get() and __set().

-Andrei   http://www.gravitonic.com/
* I wish life had an UNDO function. *

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-13 Thread Alan Knowles
Actually looking at this in more detail, the solution PHP has infers 
that using $object-XXX='somevar' is heavily prefered over 
getXXX()/setXXX(), kind of against the grain for a classic OOP language 
(from the impressions have read), As refactoring (which is often the 
logic cited for setXXX()/getXXX() ) is handled by __getXXX() / __setXXX()

Obviously $object-XXX is going to be faster than $object-getXXX(), 
Would you say that the language design inherintly suggests you use 
$object-XXX.  (and basically forget about getXXX() methods?)

Or can any think if there any other reasons why $object-XXX = 'yyy' is 
normally disuaded in classic OO design.. (and I'm not talking about 
private variables :)

Regards
Alan



Andrei Zmievski wrote:

On Wed, 13 Nov 2002, John Coggeshall wrote:
 

I understand what your saying, however I guess I see the tradeoff of
creating a new reserved word to a (IMHO of course) kinda messy new
syntax a good one. 

Besides, having an absolute standard for get/set would be benefital to
all developers.. Knowing that setting $foo is always setfoo() (or
set_foo(), makes no difference) would be nice. 
   


We do have an absolute standard: __get() and __set().

-Andrei   http://www.gravitonic.com/
* I wish life had an UNDO function. *

 




--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread John Coggeshall
|syntax:
|   var [getter method] [setter method] $variable .;

I think this syntax looks pretty interesting. It would allow the
developer to create get/set if desired and doesn't look too strange
either..

I'd like to see it in action myself :)

John


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread Marcus Börger
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


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread Shane Caraveo


Anyway before I get carried away and actually test this :) - anybody got
any thoughts.

Regards
Alan



What's wrong with how overload does this?

SHane


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread Alan Knowles
Shane Caraveo wrote:




Anyway before I get carried away and actually test this :) - anybody got
any thoughts.

Regards
Alan




What's wrong with how overload does this? 

it has a slight downside in clarity of code - eg. where is that method.. 



SHane





--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread Shane Caraveo
Alan Knowles wrote:


Shane Caraveo wrote:



 Anyway before I get carried away and actually test this :) - 
anybody got
 any thoughts.

 Regards
 Alan




 What's wrong with how overload does this?


it has a slight downside in clarity of code - eg. where is that method..

But it (overload) also does not introduce new syntax, requires no 
changes to the engine, is genericly overrideable in extensions, etc. 
etc. etc.

Shane


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread John Coggeshall

What about something like this...

Class foo {

var $myfoo; // Private variable
pubvar $myfoo2; // Public variable


}

Class bar extends foo {

pubvar $mystuff;

}

$a = new foo();
$a-setmyfoo2(5);
echo $a-getmyfoo2();

$b = new bar();
$b-setmyfoo2(10);
$b-setmystuff(20);

The point here is that pubvar automatically creates get* and set*.. As
far as overloading, etc is concerned, there would be no need to worry
about it -- the point of these functions is not to overload them (they
should simply be used to get and set member variables)... 

John

|-Original Message-
|From: Shane Caraveo [mailto:shane;caraveo.com] 
|Sent: Tuesday, November 12, 2002 10:04 PM
|To: Alan Knowles
|Cc: [EMAIL PROTECTED]
|Subject: Re: [PHP-DEV] prototypes for getters and setters.
|
|
|Alan Knowles wrote:
|
| Shane Caraveo wrote:
|
| 
| 
|  Anyway before I get carried away and actually test this :) -
| anybody got
|  any thoughts.
| 
|  Regards
|  Alan
| 
| 
| 
| 
|  What's wrong with how overload does this?
|
|
| it has a slight downside in clarity of code - eg. where is that 
| method..
|
|But it (overload) also does not introduce new syntax, requires no 
|changes to the engine, is genericly overrideable in extensions, etc. 
|etc. etc.
|
|Shane
|
|
|-- 
|PHP Development Mailing List http://www.php.net/
|To unsubscribe, visit: http://www.php.net/unsub.php
|
|


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread Alan Knowles
the trouble is that you will make pubvar a reserved word, and you force 
the user to use a fixed standard for set/get -- eg. some users may like 
get_orange, others may want getOrange
It also makes the assumtion that the user knows how the syntax works.. - 
eg. searching the file for  getOrange would return nothing...

Regards
Alan

John Coggeshall wrote:

What about something like this...

Class foo {
	
	var $myfoo; 	// Private variable
	pubvar $myfoo2;	// Public variable


}

Class bar extends foo {

	pubvar $mystuff;

}

$a = new foo();
$a-setmyfoo2(5);
echo $a-getmyfoo2();

$b = new bar();
$b-setmyfoo2(10);
$b-setmystuff(20);

The point here is that pubvar automatically creates get* and set*.. As
far as overloading, etc is concerned, there would be no need to worry
about it -- the point of these functions is not to overload them (they
should simply be used to get and set member variables)... 

John

|-Original Message-
|From: Shane Caraveo [mailto:shane;caraveo.com] 
|Sent: Tuesday, November 12, 2002 10:04 PM
|To: Alan Knowles
|Cc: [EMAIL PROTECTED]
|Subject: Re: [PHP-DEV] prototypes for getters and setters.
|
|
|Alan Knowles wrote:
|
| Shane Caraveo wrote:
|
| 
| 
|  Anyway before I get carried away and actually test this :) -
| anybody got
|  any thoughts.
| 
|  Regards
|  Alan
| 
| 
| 
| 
|  What's wrong with how overload does this?
|
|
| it has a slight downside in clarity of code - eg. where is that 
| method..
|
|But it (overload) also does not introduce new syntax, requires no 
|changes to the engine, is genericly overrideable in extensions, etc. 
|etc. etc.
|
|Shane
|
|
|-- 
|PHP Development Mailing List http://www.php.net/
|To unsubscribe, visit: http://www.php.net/unsub.php
|
|


 




--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DEV] prototypes for getters and setters.

2002-11-12 Thread John Coggeshall

I understand what your saying, however I guess I see the tradeoff of
creating a new reserved word to a (IMHO of course) kinda messy new
syntax a good one. 

Besides, having an absolute standard for get/set would be benefital to
all developers.. Knowing that setting $foo is always setfoo() (or
set_foo(), makes no difference) would be nice. 

As for assuming the user knows how the syntax works, that'd be the same
thing with any new syntax at all... 

John


|-Original Message-
|From: Alan Knowles [mailto:alan;akbkhome.com] 
|Sent: Wednesday, November 13, 2002 12:10 AM
|To: John Coggeshall
|Cc: [EMAIL PROTECTED]
|Subject: Re: [PHP-DEV] prototypes for getters and setters.
|
|
|the trouble is that you will make pubvar a reserved word, and 
|you force 
|the user to use a fixed standard for set/get -- eg. some users 
|may like 
|get_orange, others may want getOrange
|It also makes the assumtion that the user knows how the syntax 
|works.. - 
|eg. searching the file for  getOrange would return nothing...
|
|Regards
|Alan
|
|John Coggeshall wrote:
|
|What about something like this...
|
|Class foo {
|  
|  var $myfoo; // Private variable
|  pubvar $myfoo2; // Public variable
|
|
|}
|
|Class bar extends foo {
|
|  pubvar $mystuff;
|
|}
|
|$a = new foo();
|$a-setmyfoo2(5);
|echo $a-getmyfoo2();
|
|$b = new bar();
|$b-setmyfoo2(10);
|$b-setmystuff(20);
|
|The point here is that pubvar automatically creates get* and 
|set*.. As 
|far as overloading, etc is concerned, there would be no need to worry 
|about it -- the point of these functions is not to overload 
|them (they 
|should simply be used to get and set member variables)...
|
|John
|
||-Original Message-
||From: Shane Caraveo [mailto:shane;caraveo.com]
||Sent: Tuesday, November 12, 2002 10:04 PM
||To: Alan Knowles
||Cc: [EMAIL PROTECTED]
||Subject: Re: [PHP-DEV] prototypes for getters and setters.
||
||
||Alan Knowles wrote:
||
|| Shane Caraveo wrote:
||
|| 
|| 
||  Anyway before I get carried away and actually test this :) -
|| anybody got
||  any thoughts.
|| 
||  Regards
||  Alan
|| 
|| 
|| 
|| 
||  What's wrong with how overload does this?
||
||
|| it has a slight downside in clarity of code - eg. where is that
|| method..
||
||But it (overload) also does not introduce new syntax, requires no
||changes to the engine, is genericly overrideable in extensions, etc. 
||etc. etc.
||
||Shane
||
||
||--
||PHP Development Mailing List http://www.php.net/
||To unsubscribe, visit: http://www.php.net/unsub.php
||
||
|
|
|  
|
|
|
|


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php