Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104262 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7961 invoked from network); 7 Feb 2019 01:28:50 -0000 Received: from unknown (HELO mail-yw1-f45.google.com) (209.85.161.45) by pb1.pair.com with SMTP; 7 Feb 2019 01:28:50 -0000 Received: by mail-yw1-f45.google.com with SMTP id u200so3800051ywu.10 for ; Wed, 06 Feb 2019 14:10:19 -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=bcKp748y6Y5PfLXp3zmvnvJnBBHrhQmXulM1xgKW84Y=; b=golu2e1CzwZ87kpTZcoPbxuHAFjk5PK9MMprM43G6l+uy4wLbjRJ32xZau7PqclWIx 0FbFVEzn6F/8E/6lRP1DhF0tUwzw2JK+aDqrOFYSp1iYxwiwLyvPKx71Gzm/SYN4eXxS 2H/uDlFBwcrLgz7i+YmxYkwHnibiBvogQ41OCkWzw0/4ojWowPxoupoXZ+ICPrPNz5KG R1qwr09Bynjs4N12xyTvth1eX1y0mwKamH9xad61k0iK/wg4I6/L/ckbx01VZ2mJnzgT zwBL9Q/b1WVmVGwrnnPlzdKmvZBZumrS303JdTgc7AgieVx7iBsCeGWjbH/NuzTrqHw8 LuaQ== 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=bcKp748y6Y5PfLXp3zmvnvJnBBHrhQmXulM1xgKW84Y=; b=BZjsO0U6Ld5eFCbWvcknUcEnA0EdBkooHney2Xz+x9VtmhVrjbip+u/E3Pv011Tetb s0EM3rzPF0Hg4JOhmT5NIT58OwPgpQygVhxLukfwEjOIfBVOlEOKbSZDvp/jGUQgoleY bKdUydFvTc7Ac6SnomjZi31s5z3FnMRgx2IFUbnyWMUHeiAnEPZNvM9qBazpStoGroqR WDvRFP/h4otIzPyda1J52bQdjsUfUYu3kmgt2ABdRmUbkqmYCtSJMWA2XaX2vnMAPBD8 GiPTk6C3oEsYwlsKLGb8lDtRzYdqIxWeQ4lbaap6t4F1qNyfyJTc2PJUjlsyO6DAM4Zd fI2g== X-Gm-Message-State: AHQUAuZLolNgGoxnqvTPCunmcGjNqBINrUzKCKHT4z/WtAhLuX+QRpWi FuKZd5ggEow4fnmZS1ak+InyLNbXiiYse5100IM= X-Google-Smtp-Source: AHgI3IZWYVmAPpHKBFEYnb+AcvhqYgsn2uCVICXhiWeH98ITdO3coWXy+w8st1mEnKLSNmIwv7iu5IjYcloIvBw2auQ= X-Received: by 2002:a81:5507:: with SMTP id j7mr10570909ywb.491.1549491019140; Wed, 06 Feb 2019 14:10:19 -0800 (PST) MIME-Version: 1.0 References: <595b374c-bc4f-9b8a-0013-6485abbfb477@php.net> <41D0A782-E4E2-4B98-9C5D-174143DE9A76@gmail.com> In-Reply-To: Date: Wed, 6 Feb 2019 23:10:06 +0100 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000c75192058140fd3c" Subject: Re: [PHP-DEV] Re: [RFC] [VOTE] Typed properties v2 From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000c75192058140fd3c Content-Type: text/plain; charset="UTF-8" I agree that what you say conceptually makes sense; however, in a pragmatic world we usually deal with a single User class, and at some point we might want to optimize a script that was accepting a User object, but was only using, say its id and name. Doctrine already allows this, with a caveat: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/partial-objects.html You usually know where you loaded your User anyway; plus, it will still be easier to debug an uninitialized property Error that will occur straight away, rather than a null reference that can be passed along before erroring somewhere else. But we digress, can we focus on whether to add another isset()-like construct, or a property_is_initialized() function, ideally with a companion opcode to speed it up? Thank you, Ben On Wed, 6 Feb 2019 at 18:38, Rowan Collins wrote: > On Wed, 6 Feb 2019 at 15:21, Benjamin Morel > wrote: > >> You're right, in most of the cases properties SHOULD be set by the >> constructor. I do find the current behaviour interesting, however, from a >> data mapper point of view: you might want to retrieve a partial object from >> the database, and get an Error if you accidentally access an uninitialized >> property, as opposed to the pre-typed properties era, where you would get >> null and the "error" would be silenced. >> > > The problem with that is, the code doing the partial loading might be > thousands of lines from the code "accidentally" accessing the property. If, > for example, a User class supported partial loading of this sort, any > function that takes a User would have to handle the possibility that what > was actually passed was a partial User. If an error was raised, it would > require tracing back through the code to work out where the conversion from > partial to full object should have happened. > > A cleaner implementation would have PartialUser as a different type, which > could not be passed to a function expecting a User; it would then be clear > that a specific code needed to perform a conversion to fetch the rest of > the data, e.g. function getUserFromPartial(PartialUser $partial): User > > In other words, if the definition of User includes a non-nullable property > $name, then any object that doesn't have a value for $name is not actually > a User object. > > Regards, > -- > Rowan Collins > [IMSoP] > --000000000000c75192058140fd3c--