Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64660 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74422 invoked from network); 8 Jan 2013 09:04:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jan 2013 09:04:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.174 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.210.174 mail-ia0-f174.google.com Received: from [209.85.210.174] ([209.85.210.174:56482] helo=mail-ia0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/00-08647-411EBE05 for ; Tue, 08 Jan 2013 04:04:20 -0500 Received: by mail-ia0-f174.google.com with SMTP id y25so131523iay.33 for ; Tue, 08 Jan 2013 01:04:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=cZZpidlqTT3fYdvYo1tIa4nExonky7Xewgruy5F+VC4=; b=aZ5J4rgSmzsuOrnjtrVZc/kpklLzyYtykydybLBJ4GiDsK+KRlY9BMjniIeuKieiRk dKOLd+yU6SeTE5ntasKl3rO7fJAXWXLy37fRKdNfh2m23EYcyenfXIS1X6F6dns0cFyo J2+UCY2nUjKQdbLO51xUHh7XN3T9Tb16z5cKC2S9SldTA/2BQ2KVwjMncQ+ihe/zVHt6 iQK9bafVEAwVjWEyCmq39vPVvGFUaHG6mV64Euy0ZTXrWbAzK/svCsD6dhw0ySuOHn1K l7Aua9QEkhttAYyRLt5oh5i97Jj9ZX1VrBK7Dd/UE8ai2qOr0smW4pE5zSpq4jtZ0LQY WzJA== X-Received: by 10.50.152.240 with SMTP id vb16mr7819603igb.90.1357635857765; Tue, 08 Jan 2013 01:04:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.143.67 with HTTP; Tue, 8 Jan 2013 01:03:56 -0800 (PST) In-Reply-To: <50EBD4C4.8090703@toolpark.com> References: <4ED7146272E04A47B986ED49E771E347BB3D6ABCB3@Ikarus.ameusgmbh.intern> <50EBD4C4.8090703@toolpark.com> Date: Tue, 8 Jan 2013 10:03:56 +0100 Message-ID: To: Lars Schultz Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=e89a8f3ba01b09561004d2c33bbd Subject: Re: [PHP-DEV] [RFC] Alternative typehinting syntax for accessors From: linepogl@gmail.com (Lazare Inepologlou) --e89a8f3ba01b09561004d2c33bbd Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > It takes up the syntax php has been using for method-definitions. The fact is that the existing syntax for nullable type hinting has its own problems. For example, this is not possible: function foo( Bar $bar =3D null , $mandatory ) { ... } I would love to have the question mark syntax for both properties and argument type hinting. > Although, as Stas has pointed out, *not* allowing NULL for a property will not prevent it from being NULL...depending on wether it has been initalized. This does not apply in all cases. Here is an example of a property that is guaranteed not to be null: class Foo { private $_date; public DateTime $date { get { return is_null($date) ? new DateTime() : $this->date; } set { $this->date =3D $value; } } } Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel 2013/1/8 Lars Schultz > Am 08.01.2013 08:56, schrieb Christian Stoller: > >> But the way 'nullable' properties are defined is not very intuitive and >> unclean, in my opinion. Stas has already mentioned that. >> `public DateTime $date =3D NULL;` // this looks like the property is >> initialized with null, but it does not show that the property is 'nullab= le' >> > > To me this makes perfect sense. It takes up the syntax php has been using > for method-definitions. A syntax we would be using to create a classic > setter method if there wasn't a fancy new one. > > public function setDate(DateTime $date =3D NULL) { > $this->date =3D $date; > } > > Anything other than this would result in an inconsistency. Having accepte= d > that syntax previously and now introducing yet another one, would be > confusing and unnecessary. > > Although, as Stas has pointed out, *not* allowing NULL for a property wil= l > not prevent it from being NULL...depending on wether it has been initaliz= ed. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --e89a8f3ba01b09561004d2c33bbd--