Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104242 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46966 invoked from network); 6 Feb 2019 15:57:10 -0000 Received: from unknown (HELO mail-yb1-f170.google.com) (209.85.219.170) by pb1.pair.com with SMTP; 6 Feb 2019 15:57:10 -0000 Received: by mail-yb1-f170.google.com with SMTP id k189so2389462yba.11 for ; Wed, 06 Feb 2019 04:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VqoA+qgqcOfJeeSMFiou72WXOzub+qXBJBnolzB8RAo=; b=mdiicwoxWLEbU+xntir+tF5eg5gAaJw4/Oz+MmcaK/Gyh2AAgSBtEioQEiELjuD16r X4tjYvDJdII0g8sHEMx4YojXJgEWtNndLhUsZuSMH19iVnEJJ/26CtNFeny3KUeW2dzo LfttgEBRrg2uo7CJn8G9w0RdqDM+3vjhA8F05/bKYHg/7EAuSE+N8+yZ/hWxJcKsam/S 5SMQDgQbM43SPfC2BDBBWsptQ9h1QRNzAZHzSZsibFpOv3kX0Kyzq68GE/QgV2bY4ee1 y3i7bVt2AvymwtDNRG1wGJkW3ulDcf9Pfh4bFdhSXoyI9Ebrin4sTmCek7ms2EzxM9z9 Yptg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VqoA+qgqcOfJeeSMFiou72WXOzub+qXBJBnolzB8RAo=; b=nuPU7h3ICo4tFKOalxLkraEawEYHFHesL0wCrfUxL4/iVVy+puj4T5v1/hxw4FUu3a STAglx6EYahS39TQvVUscU3zngYg5XV5BgLZlO8WuhCx1CpqJKK2abZIOfSOJ8fvlpQz AylgOZYfgSA0qMYfe+BTsfPEBr17RmhDvGvdLSI0ZzIa3ey1jxQAZa0/+8yVJf4/gYrr W0PfH+4M/ASXdVjHnOLcEXqw0sFmIbfAYxtDJPk6H00lSyQl3hNFkK0Bnmt1sFTlt1FY lNbq3AlZSewh3PLSamUAmA7NfX0j1y50VSnwg862Do9QP43dKpv/QBED2H+KLojDRK/s eF8g== X-Gm-Message-State: AHQUAubKcTQXisLzHBXx6GD+dqVZCbnkP7qA3ks6nf3bbKG6XY1Qsv3/ jls3UjyZB+LZ4M6Qwdh4o2ixwCIyAItUbwueMYo= X-Google-Smtp-Source: AHgI3IZSCiriQWVYlB8n3UAWrFSE/Q8yRTnvLgeYmYvuy4m1mj2ihiH0r/Hf8Lt953eN/4hbyHrsL6owJ9lBj0FkvSs= X-Received: by 2002:a25:a361:: with SMTP id d88mr8418149ybi.317.1549456712577; Wed, 06 Feb 2019 04:38:32 -0800 (PST) MIME-Version: 1.0 References: <595b374c-bc4f-9b8a-0013-6485abbfb477@php.net> In-Reply-To: Date: Wed, 6 Feb 2019 13:38:20 +0100 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000f2ba2e05813900b4" Subject: Re: [PHP-DEV] Re: [RFC] [VOTE] Typed properties v2 From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000f2ba2e05813900b4 Content-Type: text/plain; charset="UTF-8" Hi Nikita, While playing with typed properties, something that annoys me a lot, in the context of a data mapper, is not to be able to use isset() to check whether an object's property is initialized. The issue was already there with properties that have been explicitly unset(), but will be exacerbated by typed properties, which will be unset *by default*. Sure, we have ReflectionProperty::isInitialized(), but reflection is slow compared to direct property access, when reading a lot of objects. For example, check these 3 ways of reading initialized public/protected object properties by name, along with their timings for 100,000 iterations (benchmark here ): Using reflection: (890 ms, down to 384 ms using pre-instantiated ReflectionProperty objects) $r = new \ReflectionClass($class); > foreach ($props as $prop) { > $p = $r->getProperty($prop); > $p->setAccessible(true); > if ($p->isInitialized($object)) { > $values[$p->getName()] = $p->getValue($object); > } > } Using array cast: (193 ms) foreach ((array) $object as $key => $value) { > // Remove the "\0*\0" in front of protected properties > $pos = strrpos($key, "\0"); > if ($pos !== false) { > $key = substr($key, $pos + 1); > } > $values[$key] = $value; > } Using a bound closure and isset(): (145 ms) > (function() use ($props, & $values) { > foreach ($props as $prop) { > if (isset($this->{$prop})) { // skips NULL values as well :-( > $values[$prop] = $this->{$prop}; > } > } > })->bindTo($object, $object)(); Unfortunately, while the last approach is the fastest, and IMO the cleanest one, it is currently unusable because there is no way to differentiate between an uninitialized property and a NULL property. Would it be possible to introduce another isset() operator, that would return true for NULL values? Note that this would also be useful when checking if an array key exists, instead of having to switch from isset() to array_key_exists() when the array may contain NULL values. Ben On Fri, 11 Jan 2019 at 17:38, Nikita Popov wrote: > On Mon, Oct 22, 2018 at 1:58 PM Sebastian Bergmann > wrote: > > > Am 26.09.2018 um 15:46 schrieb Nikita Popov: > > > I'm pleased to announce that the typed properties RFC has been accepted > > > with 70 votes in favor and one vote against. We will work to finalize > and > > > merge the implementation in the next few days. > > > > Any update on when this will be merged? Thanks! > > > > Sorry for the long delay here. I've spent the last week fixing the > remaining issues and cleaning up the patch, and... > > ...Typed properties are now merged into master! [1] > > It would be great if people could start experimenting with typed properties > (e.g. by migrating over existing @var annotations and seeing what happens). > The earlier we find issues in the implementation or semantics, the better. > > Thanks to everyone who worked on this RFC and participated in discussions. > Special thanks to Bob Weinand who did most of the initial implementation > work on this RFC. > > Regards, > Nikita > > [1]: > > https://github.com/php/php-src/commit/e219ec144ef6682b71e135fd18654ee1bb4676b4 > --000000000000f2ba2e05813900b4--