Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63303 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78719 invoked from network); 9 Oct 2012 13:01:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Oct 2012 13:01:10 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:35404] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/C8-23861-41024705 for ; Tue, 09 Oct 2012 09:01:09 -0400 Received: by mail-lb0-f170.google.com with SMTP id gm13so3754595lbb.29 for ; Tue, 09 Oct 2012 06:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=4TmNxsuH5TJ/wLi7gTa3sMwzTUU8touvNqXtnP6CuE4=; b=QhdLt31CdrTOCdj67aT5BSYlorYyZbqjSj4La6Dpc/lVx+xuChGwSn0dOlXj3WpsqV 9u/lgK1oXBDbOB8QB8MrfHINdPOuvk1RHUp1NmXYLEBGZIWNeZOeuk1VyGqJL/NHdeN6 B2ggEH3u+dlNbXG2t7E8ntOYG6BOlozQg7NqAQAmWuU5d3esDhBvwxXiQtpNze0nIhcg 1EFFcSIzPml7Ju2aefNQK6ju1C8+a5MIOkIwdpLNmAOAWkOZaHZyzVEKReCchObjamJC FyasiTgNU39XnLOKF73ktl+KX8pR/1zbSHI7upWlqoaMSgWcLe1ZfpEguD2ojQCQxbax HEcw== MIME-Version: 1.0 Received: by 10.152.108.37 with SMTP id hh5mr16550083lab.52.1349787665836; Tue, 09 Oct 2012 06:01:05 -0700 (PDT) Received: by 10.112.83.100 with HTTP; Tue, 9 Oct 2012 06:01:05 -0700 (PDT) In-Reply-To: <9570D903A3BECE4092E924C2985CE485612B3B48@MBX202.domain.local> References: <9570D903A3BECE4092E924C2985CE485612B3B48@MBX202.domain.local> Date: Tue, 9 Oct 2012 15:01:05 +0200 Message-ID: To: Clint Priest Cc: "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 From: nikita.ppv@gmail.com (Nikita Popov) On Mon, Oct 8, 2012 at 1:52 PM, Clint Priest wrote: > 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. What concerns me with the current implementation is that it leaks many implementation details, in particular the fact that the accessors are implemented as *real* __getXYZ methods and automatic implementations also use *real* $__XYZ properties. A few examples: ## 1 - __getProperty() method directly callable class Test { public $property { get { return 123; } } } $test = new Test; var_dump($test->property); // int(123) var_dump($test->__getProperty()); // int(123) ## 2 - __getProperty() method exposed via exception class Test { public $throwingProperty { get { throw new Exception; } } } (new Test)->throwingProperty; exception 'Exception' in /home/nikic/dev/php-src/t29.php:9 Stack trace: #0 /home/nikic/dev/php-src/t29.php(31): Test->__getthrowingProperty() #1 {main} ## 3 - Can directly access $__automaticProperty and even unset it (causing notices in the internal code) class Test { public $automaticProperty { get; set; } public function getAutomaticProperty() { return $this->__automaticProperty; } public function unsetAutomaticProperty() { unset($this->__automaticProperty); } } $test->automaticProperty = 'foo'; var_dump($test->getAutomaticProperty()); $test->unsetAutomaticProperty(); var_dump($test->automaticProperty); string(3) "foo" Notice: Undefined property: Test::$__automaticProperty in /home/nikic/dev/php-src/t29.php on line 13 NULL ===== I feel like this approach to the implementation will be a big can of worms. Sure, it works, but it is rather fragile and the enduser ends up dealing with internal stuff which he ought not care about. I think it would be better to cleanly separate out the accessor implementation. It might require more code now, but will be better in the long run. Nikita