Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50701 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70274 invoked from network); 29 Nov 2010 17:51:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2010 17:51:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=jbondc@openmv.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jbondc@openmv.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain openmv.com from 64.15.152.204 cause and error) X-PHP-List-Original-Sender: jbondc@openmv.com X-Host-Fingerprint: 64.15.152.204 mail.ca.gdesolutions.com Received: from [64.15.152.204] ([64.15.152.204:49348] helo=mail.ca.gdesolutions.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8E/44-42097-D38E3FC4 for ; Mon, 29 Nov 2010 12:51:57 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.ca.gdesolutions.com (Postfix) with ESMTP id B88675D35; Mon, 29 Nov 2010 12:51:54 -0500 (EST) X-Virus-Scanned: amavisd-new at gdesolutions.com Received: from mail.ca.gdesolutions.com ([127.0.0.1]) by localhost (mail.ca.gdesolutions.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mBAUSilv1iL7; Mon, 29 Nov 2010 12:51:54 -0500 (EST) Received: from djbondc (modemcable083.208-56-74.mc.videotron.ca [74.56.208.83]) by mail.ca.gdesolutions.com (Postfix) with ESMTP id 41E095D18; Mon, 29 Nov 2010 12:51:54 -0500 (EST) To: "'Stas Malyshev'" Cc: , References: <003601cb8fd0$f6494e80$e2dbeb80$@com> <4CF3B855.5010406@sugarcrm.com> In-Reply-To: <4CF3B855.5010406@sugarcrm.com> Date: Mon, 29 Nov 2010 12:51:53 -0500 Message-ID: <003401cb8fee$1be39840$53aac8c0$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcuP0aKnayKxKGMxSd2D3HA7DuzyqgABRU5Q Content-Language: en-ca Subject: RE: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: jbondc@openmv.com ("Jonathan Bond-Caron") On Mon Nov 29 09:27 AM, Stas Malyshev wrote: > Hi! > > > Nice RFC, just an idea for an alternative syntax (added to the RFC > > as > #2): > > > > property Hours { > > get { return $this->seconds / 3600; } > > set { $this->seconds = $value * 3600; } // The variable $value > holds > > the incoming value to be "set" > > } > > > > class TimePeriod > > { > > private $seconds; > > > > public [Hours] $hours1; > > public {use Hours;} $hours2; > > } > > If you change "property" to "class" or "trait" and "get" to "__get" > you need almost no new syntax :) > Right, it looks the same but the subtle difference is 'property Hours' wouldn't be registered as a class. It's just container code for get(), set() methods that would get 'compiled' into opcodes in the class TimePeriod (the property exists vs. searching for it in runtime). So you can think of it as a special 'trait' that only applies to properties. The idea behind this syntax is you can move the 'property' definition out of the class so that you can test and re-use it somewhere else (like traits). That might not be problem if you can define properties in traits (needs to be explained in the RFC): trait TimeUnits { public property Seconds { get { return $this->seconds; } set { $this->seconds = $value; }// The variable $value holds the incoming value to be "set" } public property Minutes { get { return $this->seconds / 60; } set { $this->seconds = $value * 60; } } public property Hours { get { return $this->seconds / 3600; } set { $this->seconds = $value * 3600; }// The variable $value holds the incoming value to be "set" } } class MyTime { uses TimeUnits; protected $_seconds; }