Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97767 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45195 invoked from network); 15 Jan 2017 23:28:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jan 2017 23:28:06 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wm0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:36805] helo=mail-wm0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/60-00729-4850C785 for ; Sun, 15 Jan 2017 18:28:05 -0500 Received: by mail-wm0-f53.google.com with SMTP id c85so137358512wmi.1 for ; Sun, 15 Jan 2017 15:28:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=zLRYSYiUXQJ/3stANYxMsYvvCPwyHx2a1nQmD2hsnB4=; b=m+7+mYt+5cTkEUM+1I81nBdj2A5tFzffawZ4ubreXpSthShepfSyGlG2zz2Lr6/FBc vexXmwVIctMuGwe2gqDXUOUnXgQ+9pkSfkc3EPs1GvrILe6sNpu/zTkQ7RqTUXrGrUuY 6fp3xI8T3vla8se1tvTk78jYrKlTPKaIe476hxvANl3sDsXM76gtsJmedfKlNt1gYEcs vNJM/iRxYayVbNcfy+7uSrs0DpcVSOwmHNrsFxj7UA3bXXifTznP6SIS+onYgikJJrYk ACqj2bqX9utnyWr5LVjHfCS9gMOUU0sHoICvr7wQeEHw4w4r0lEsCyTZ+BgbFfJsX2+D OvMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=zLRYSYiUXQJ/3stANYxMsYvvCPwyHx2a1nQmD2hsnB4=; b=YqeKqv3lxhy+DQOMOQoozLRDGsjGGEmiR8LhgAXqgBB5/GTVc8uufcxXs7Gch5FuYy dMgAEapPdErbtD5y45PK3C9tBR1f6N+ZYnOLLgGx3VEfJVrNj2SfklfXXSlD9DtpKg78 ZsXZdX00emLvEsdMF19K/u/xxonW0HIjUOjDNZGWIMsl4nrOdeKnP5vKRf/ag9CzrIir kht00+ExsiQHcmG0PgmTKDz7NgeLdms9MCpmbIMH9p/h3DXU8eD9+wsM8SSCC7NxBkvg /3X223WlVgpifRnC8t8dvcoYiaqHSXkiwqj3vzIKQqzK6NcblT4iXP/+L/dnsO/qP7Zq fDgw== X-Gm-Message-State: AIkVDXIRv2Lz7mUA5Cahg3Szid7lcVOVPuxjUR6ZR6khSxEoZMcP74tzTzmc0VuTzd8bOgKSrXTPxMOnXCHJyw== X-Received: by 10.223.154.132 with SMTP id a4mr23565542wrc.188.1484522881739; Sun, 15 Jan 2017 15:28:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.34.197 with HTTP; Sun, 15 Jan 2017 15:27:41 -0800 (PST) In-Reply-To: References: Date: Mon, 16 Jan 2017 00:27:41 +0100 Message-ID: To: Wes Cc: PHP Internals Content-Type: multipart/alternative; boundary=f403045f558006f3d805462a6b45 Subject: Re: [PHP-DEV] Unsetting declared fields From: ocramius@gmail.com (Marco Pivetta) --f403045f558006f3d805462a6b45 Content-Type: text/plain; charset=UTF-8 Hi Wes, This has been discussed before, and it's currently used to intercept access to properties. Since we don't have property accessors (sigh), the code (simplified version) would look like following: class Foo { public $bar = 'baz'; } class FooInterceptor extends Foo { private $wrapped; public function __construct(Foo $wrapped) { $this->wrapped = $wrapped; unset($this->bar); } public function __get(string $name) { var_dump('reading ' . $name); return $this->wrapped->$name; } } $foo = new FooInterceptor(new Foo); var_dump($foo->bar); You can see a working example at https://3v4l.org/UtugD This behavior is protected from regressions since PHP 5.4, but has been working since 5.0: https://github.com/php/php-src/blob/cd2b462a2742c79256668d4736644e34573c33d9/tests/classes/unset_properties.phpt We can most probably get rid of this weird behavior once property accessors are in the language. Greets, Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On Mon, Jan 16, 2017 at 12:20 AM, Wes wrote: > Hello elephpants. > > Currently PHP allows explicitly declared fields (eg public $foo = 10;) to > be removed entirely through unset (eg unset($obj->foo)). > > Now that isn't really an issue as properties in php are currently untyped > and therefore nullable; at worst you would get a notice. But it would > become an issue with typed fields... that might get a second chance sooner > or later. > > But regardless of that, it looks very strange to me that this is allowed > for fields that are explicitly declared. I think unset() should set the > field to null if it's declared in the class, and remove the field > altogether only if it was defined dynamically. > > On the other hand, this is just one of many ways of hacking php that just > exist and we accept / don't care because we have faith in other people not > doing nasty stuff with our code. This might sound ironic it is actually not > :P > > However, I am curious: what you think about this? Should PHP do something > in regard? Should this continue to work like it does now? Why do you feel > it should do the one or the other? > --f403045f558006f3d805462a6b45--