Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88258 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42688 invoked from network); 16 Sep 2015 19:57:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Sep 2015 19:57:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=rewilliams@thesba.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rewilliams@thesba.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain thesba.com designates 208.106.205.210 as permitted sender) X-PHP-List-Original-Sender: rewilliams@thesba.com X-Host-Fingerprint: 208.106.205.210 ntsexchedgea1.newtekemail.com Received: from [208.106.205.210] ([208.106.205.210:56280] helo=NTSEXCHEDGEA1.nts.phx1) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/00-41443-E89C9F55 for ; Wed, 16 Sep 2015 15:57:03 -0400 Received: from NTSMAILBOX2.NTS.PHX1 (208.106.205.233) by NTSEXCHEDGEA1.nts.phx1 (208.106.205.210) with Microsoft SMTP Server (TLS) id 15.0.847.32; Wed, 16 Sep 2015 12:56:31 -0700 Received: from NTSMAILBOX1.NTS.PHX1 (2002:d06a:cde8::d06a:cde8) by NTSMAILBOX2.NTS.PHX1 (2002:d06a:cde9::d06a:cde9) with Microsoft SMTP Server (TLS) id 15.0.847.32; Wed, 16 Sep 2015 12:56:23 -0700 Received: from NTSMAILBOX1.NTS.PHX1 ([fe80::51f0:160d:841f:d989]) by NTSMAILBOX1.NTS.PHX1 ([fe80::51f0:160d:841f:d989%13]) with mapi id 15.00.0847.030; Wed, 16 Sep 2015 12:56:22 -0700 To: Rowan Collins CC: "internals@lists.php.net" Thread-Topic: [PHP-DEV] PHP 7.1 - Address PHPSadness #28? Thread-Index: AQHQ36zP6Wb5e1HnokKnJlazAkejtZ4eJ62AgABxe4CAAAPLgIAAJlKAgAAUa4CAACGZAIAAGymAgAjS3QCAAJOjgIAA+D+AgAA5fACAB+afgIAB6WsAgAFo8ICAACyWAIAHac+AgAAGeYCAAD+qgIAAAnkAgABF9ACAAAG1gIAAJ92AgAAFuoCAADs0MIACTzKAgAA+UICAAApMAIAAHJoA Date: Wed, 16 Sep 2015 19:56:22 +0000 Message-ID: <61163E50-AF39-4F69-B740-7F2D40129DB1@thesba.com> References: <8C74463E-DBA2-4015-8159-0B44D973387F@craigfrancis.co.uk> <55DE0907.6040904@gmail.com> <1F615BCD-1B9B-4C51-A210-869F1AA1F6E3@craigfrancis.co.uk> <55E5EBBF.6020803@gmail.com> <0BA3A129-D356-4781-B6DE-E2B5A7924AE2@craigfrancis.co.uk> <55E6EC36.6090301@gmail.com> <9AF329EC-99A5-412D-A52B-432627A5520F@gmail.com> <6F4D91EE-B56E-4B83-B1AF-598C3F6897FC@craigfrancis.co.uk> <55F07BA4.2000204@gmail.com> <55F6B911.9080400@gmail.com> <96BE7F01-D04B-483B-B1A3-B45CED6DFCDC@craigfrancis.co.uk> <55F6F08C.1020506@gmail.com> <0BEF6D82-CB5F-49F6-A3A4-3267924A0CDA@thesba.com> <55F72CA9.2060301@gmail.com> <09369945-76FE-4E08-9C2C-15FB0577AD27@thesba.com> <55F752E7.9070801@gmail.com> <55F9747F.4070708@gmail.com> <738E9B97-6D20-4E37-85E0-994003ACDFC1@thesba.com> <55F9B168.9010007@gmail.com> In-Reply-To: <55F9B168.9010007@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [172.16.153.36] Content-Type: multipart/signed; boundary="Apple-Mail=_6B0F4D39-86D3-4784-9D8E-A24EF97F99E3"; protocol="application/pgp-signature"; micalg=pgp-sha512 MIME-Version: 1.0 Subject: Re: [PHP-DEV] PHP 7.1 - Address PHPSadness #28? From: rewilliams@thesba.com (Robert Williams) --Apple-Mail=_6B0F4D39-86D3-4784-9D8E-A24EF97F99E3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On Sep 16, 2015, at 11:14, Rowan Collins = wrote: >=20 > Robert Williams wrote on 16/09/2015 18:37: >> The docs suggest that uninitialized variables are null, and the above = makes it sound like that=92s what you=92re stating, too. But they=92re = not: they don=92t exist at all, they=92re uninitialized. >=20 > As soon as you access them, you will get the value null. You can do = everything with them that you could do with a variable initialised to = null. As soon as you access them, you get an error, and then you get null. = Yeah, one could register an error handler, but that=92s a lot of fuss = just to see if a variable really exists or just exists because you = accessed it, and it pulls you out of context. Basically, there=92s no = (clean, very simple) way to identify that you=92re about to step in a = pile of poo before you step in it. >> If they were null, then PHP wouldn=92t spit out errors about = undefined variable accesses >=20 > Once again - PHP does not spit out errors when you access an undefined = variable. It spits out Notices in case you've done it by mistake. Maybe = you're thinking of JavaScript? In our shop, notices are most definitely errors. And notices aren=92t = graceful error handling. I think PHP also also regards them as errors = (thus the ability to catch them with an error handler) - it=92s just a = lower grade of error. > I don=92t think it=92s a huge gap in the language, but it=92s a = definite gap, and it=92s one that many less-experienced programmers fall = right into with safety checks. >=20 > There is no safety check required. If you care about eliminating the = Notices, then initialise all your variables properly, and you will never = have an uninitialised variable (so a runtime check for one would be = pointless). If you don't care about eliminating the Notices, then simply = treat uninitialised variables as Null, and they will work absolutely = fine. That=92s great in theory, but in practice, programmers=92 code must = frequently collaborate with other people=92s code, often code from = outside their organization. In these cases, they don=92t have the = control to just fix the problem on the other side. And in some cases, = like with config files that set bare variables, there=92s really nothing = wrong with the way it=92s done that needs to be fixed. Some folks might = prefer to use a different model, but that=92s just a preference. Adding an exists() function doesn=92t go against the foundation of PHP. = It just fills a gap. Again, I can define variables, and I can destroy = them, but I can=92t tell if they=92ve already been defined. In a dynamic = language like PHP, I really don=92t understand how folks can *not* see = that as an oversight. Further, we can do this for everything else=85 = constants, array elements, object properties, functions, and even = classes, so why not variables? There's even have precedence for = controlling behavior based on variable existence in extract(), so PHP = itself does it in ways that directly affect the user, but the user can=92t= do it. Yes, there are workarounds for the gap. There are almost always = workarounds in a sufficiently developed language, but that doesn=92t = mean there isn=92t a gap. -Bob --Apple-Mail=_6B0F4D39-86D3-4784-9D8E-A24EF97F99E3 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="signature.asc" Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJV+cllAAoJEFBTSdRZ0ub3h58P/jP/2RgEXDGm+t3MjrVCa5nd u7IBy8gL4RigMOseVMgassPDWwlNfEtINciysVzXoUnSq2TA68wkQoYp4jUgTTwA ZMSRkjfWGuSondhMp8ceO7yui/eGQyUsz7RmHkSnYojR3HEXP49+dA1z+g9AMzP1 KLX17t54WUFaWMeWUw2ILEL6zhwzca0Vml3y2XxaCc1BOECLEXyxFIWzL9RcyQCN 22zxW6mMs0QLauocc5uMybGKN/a/gdCHkzSDtnMoYCpOGb7/3ufY8qr2CPY2e4++ eAuuHjSlBJUga9Hxr+RC44MS+aMXVFuyZHl3klkTYQy3NTRC4za5ID2fUx7MrT4V KynvWK0FCSyGfIt1RDL/3n2c9xSlVe/WJgafOcWTP4jSPPH4hr+dkwDktpLqOZ/O Sksfn4ZFsoKiTzq/V7O0p7SpLVlZV/pHHLZ8/mjX9APgX89K+qdHyZxLlOIjclcC +h4rOk6FT9T9yQAmk/4TSKJCqHA7TorLfobXzu4Yvc2YQdffnSL2L5wysmgRVT13 CD9Plz1rY5ge6cf5x1R8Ak9s1yzokqCOl8ViqaNou78Qbdd5/3l1qkn6TS20OUDu xUkDvCC8o0+H0HIjkrH1UWl0ADs3SMZvm9c4xwpw3gN1BAFnLIrnKXW8yDn7lLMa gacKDedvDelB7aqNZ+2Y =Ytux -----END PGP SIGNATURE----- --Apple-Mail=_6B0F4D39-86D3-4784-9D8E-A24EF97F99E3--