Re: [PHP-DEV] [RFC] Property Accessors v1.2 : Internal Accessor Method Visibility / Callability

2012-11-04 Thread Cal

Le 26/10/2012 11:37, Clint Priest a écrit :
I'm opening up several new threads to get discussion going on the 
remaining "being debated" categories referenced in this 1.1 -> 1.2 
change spec:
https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented/change-requests 



In the RFC, section "read-only / write-only keywords" :


class  TimePeriod{
 private  $Seconds;
   public  $Hours  {
 get()  {  return  $this->Hours;  }
 private  final set($value)  {  throw  new Exception("Setting 
of TimePeriod::$Hours  is not allowed.");  }

 isset() { return isset($this->Seconds); }
 unset() { unset($this->Seconds); }
 }
}


I just added the methods "isset" and "unset" of the first example.

So, is there a case where "set" and "unset" shouldn't have the same 
visibility ? And "get" and "isset"?


If not, the Amaury's proposition could be merged in your syntax:


class  TimePeriod{
 private  $Seconds;
   public:private  $Hours  {
 get()  {  return  $this->Hours;  }  // read => public
 set($value)  {  throw  new  Exception("Setting of 
TimePeriod::$Hours  is not allowed.");  }  // write => private

 isset() { return isset($this->Seconds); } // read => public
 unset() { unset($this->Seconds); } // write => private
 }
}




Re: [PHP-DEV] [RFC] Propety Accessors v1.1

2012-10-26 Thread Cal

Le 08/10/2012 14:27, Amaury Bouchard a écrit :

My idea was to write attribute's visibility like
"read_visiblity:write_visibility $attr;"
   public:protected $foo; // public reading, protected writing
   public:private $bar; // public reading, private writing
   protected:private $aaa; // protected reading, private writing
   protected:const $bbb; // protected reading, no writing


I read all the messages on the property accessors. And I really agree 
with the solution of Amaury. It is a nice solution: not verbose, not 
slower, just covers most of developper's needs.


Cal

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



Re: [PHP-DEV] [PHP-DEV [RFC] Property Accessors v1.2

2012-10-12 Thread Cal


Le 12/10/2012 11:48, Nikita Popov a écrit :

I've been thinking a bit about the automatic properties again, and
noticed that I forgot to name one use case: Asymmetric accessor
visibility. Automatic properties may be useful in that context, so
that you can write "public $foo { get; protected set; }" (though they
don't necessarily need to be implemented as properties with auto
generated code, rather just properties with more detailed visibility
handling [a bit related to the stuff Amaury has been saying]).


I agree.

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



Re: [PHP-DEV] [RFC] Propety Accessors v1.1

2012-10-11 Thread Cal

(Let me suggest an idea irrelevant. Sorry...)

The performance of getters is critical.

For me the best solution would be a new keyword, equivalent to a "var" 
without write access from outside the class:


class TimePeriod {
*property*  $Hours = 1;

public function setHours($h) {
$this->Hours = $h;
}
}

$myTP = new TimePeriod();
echo $myTP->Hours; // 1
$myTP->setHours(3);
echo $myTP->Hours; // 3
$myTP->Hours = 5; // KO. PHP error here


Le 08/10/2012 13:42, Clint Priest a écrit :

As an update, just ran some performance testing:

master
Cycles  Direct  Getter  
__get
v1.4 @ 10/8/20121m  .05s.21s
.20s

php 5.5.0-dev
Cycles  Direct  Getter  
__get
v1.4 @ 10/8/20121m  .04sn/a 
.21s

Performance of property accessors was important to me as I'm sure it will be to 
many, on one million cycles of a simple getter, it's <.01s difference.  
Depending on the run it is sometimes exactly the same performance.


-Original Message-
From: Clint Priest [mailto:cpri...@zerocue.com]
Sent: Monday, October 08, 2012 6:53 AM
To: internals@lists.php.net
Subject: [PHP-DEV] [RFC] Propety Accessors v1.1

It's been a while since I posted any updates about this, a few individuals have 
been asking about it privately and wanting me to get it
out the door for PHP 5.5 release.  It's come a long way since the last time I 
posted about it.

RFC Document: https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented

Example Usage:

class TimePeriod {
 private $Seconds = 3600;

 public $Hours {
 get { return $this->Seconds / 3600; }
 set { $this->Seconds = $value; }
 isset { return 
isset($this->Seconds); }
 unset { 
unset($this->Seconds); }
 }
}

Changes / Updates

* isset/unset accessor functions now implemented (object & static 
context, auto implementations, etc)

* static accessor now fully functional

* Reference functionality validated, tests written

* All operators have been tested, tests written

* read-only and write-only keywords: Added explanation of reasons for 
inclusion at the top of the appropriate RFC section

* Tested for speed, approaches or meets __get() speed.

Internally things have changed quite a bit

* cleaned up and simplified

* had been using 4 to 5 additional fn_flag slots, now down to two 
(READ_ONLY and WRITE_ONLY)

* the automatic implementations now compiled internal php code, this 
greatly simplified that part of the code and future proofed
it.

The code is available at the url below and is up to date with master, all tests 
pass.
https://github.com/cpriest/php-src

I'd like to get this project wrapped up in time to make it to the 5.5 release, 
only a few things remain to be completed/updated:

* Check on reflection code written prior to major changes (tests still 
pass)

* Add a few more reflection functions that were requested

In total there are 79 tests for this new functionality, if there are any others 
that I have missed, please let me know.

-Clint