Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88251 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22139 invoked from network); 16 Sep 2015 17:27:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Sep 2015 17:27:52 -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.211 as permitted sender) X-PHP-List-Original-Sender: rewilliams@thesba.com X-Host-Fingerprint: 208.106.205.211 ntsexchedgea2.newtekemail.com Received: from [208.106.205.211] ([208.106.205.211:53140] helo=NTSEXCHEDGEA2.nts.phx1) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/23-04557-796A9F55 for ; Wed, 16 Sep 2015 13:27:52 -0400 Received: from NTSMAILBOX2.NTS.PHX1 (208.106.205.233) by NTSEXCHEDGEA2.newtekemail.com (208.106.205.211) with Microsoft SMTP Server (TLS) id 8.3.348.2; Wed, 16 Sep 2015 10:27:13 -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 10:27:48 -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 10:27:47 -0700 To: Rowan Collins CC: "internals@lists.php.net" Thread-Topic: [PHP-DEV] PHP 7.1 - Address PHPSadness #28? Thread-Index: AQHQ8KUB9yGTV10xrEGSpn6/L29FpA== Date: Wed, 16 Sep 2015 17:27:47 +0000 Message-ID: <51BBFC90-C83C-4112-90B5-E04C27F1746E@thesba.com> References: <55F97251.3080706@gmail.com> In-Reply-To: <55F97251.3080706@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=_42F2F2CD-A6E5-4EAE-990C-9E3A69B31FFC"; 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=_42F2F2CD-A6E5-4EAE-990C-9E3A69B31FFC Content-Type: multipart/alternative; boundary="Apple-Mail=_C60705A0-A8CD-4ED4-ADEB-50CC3C50BA81" --Apple-Mail=_C60705A0-A8CD-4ED4-ADEB-50CC3C50BA81 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 On Sep 16, 2015, at 06:44, Rowan Collins = wrote: >=20 > Can you give an example of code where you do not know this until the = code runs - i.e. where "is this variable set?" is something you can hang = business logic on? >=20 > Somewhere where it would make sense to write something like this, if = the exists() function were available for plain variables: >=20 > if ( exists($a) ) { > ... > } elseif ( is_null($a) ) { > ... > } else { > ... > } Sure. It=E2=80=99s not common with controlling business logic = (fortunately), but it is very common in error-handling code. I already = mentioned the templates, but an even more common scenario is config = files that are supposed to just define a bunch of standalone variables, = which is a very common pattern. If you=E2=80=99re writing code that = relies on those variables, or you=E2=80=99re writing the code that=E2=80=99= s supposed to pull that file in to begin with, it=E2=80=99s smart to = make sure all the variables actually got set, and if not, display an = error to the user to go fix the config. Sometimes, isset() works for = this if combined with a null check, but it fails in cases where null is = an acceptable value. -Bob --Apple-Mail=_C60705A0-A8CD-4ED4-ADEB-50CC3C50BA81 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On Sep 16, 2015, at 06:44, Rowan Collins = <rowan.collins@gmail.com> wrote:

Can you give an example of = code where you do not know this until the code runs - i.e. where "is = this variable set?" is something you can hang business logic = on?

Somewhere where it would = make sense to write something like this, if the exists() function were = available for plain variables:

if ( exists($a) ) {
...
} elseif ( is_null($a) ) = {
...
} else {
...
}

Sure. = It=E2=80=99s not common with controlling business logic (fortunately), = but it is very common in error-handling code. I already mentioned the = templates, but an even more common scenario is config files that are = supposed to just define a bunch of standalone variables, which is a very = common pattern. If you=E2=80=99re writing code that relies on those = variables, or you=E2=80=99re writing the code that=E2=80=99s supposed to = pull that file in to begin with, it=E2=80=99s smart to make sure all the = variables actually got set, and if not, display an error to the user to = go fix the config. Sometimes, isset() works for this if combined with a = null check, but it fails in cases where null is an acceptable = value.

-Bob
= --Apple-Mail=_C60705A0-A8CD-4ED4-ADEB-50CC3C50BA81-- --Apple-Mail=_42F2F2CD-A6E5-4EAE-990C-9E3A69B31FFC 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+aaOAAoJEFBTSdRZ0ub32PgQAJ3p/FEjIQAUxHz5e7nPqD89 h8ihsuCz5mURpj0EuFFoBa9zIWgf4zs0ZFS65BjQzWbMG+Qi19Bh6RXALoz/BrG+ nM75e5yHuA3SfUSZrLzFCmfBAKb9nGOi1wayKCE0xRl1zSGIHRikmMvWe8C+kyVw iaRg+zEbSN1ecLFHgz9435LGMQpsE3BSwK6oJzsPxmNIpM6mdDLzrryF/J9z6HrY ZMV3IpWZtcV6lEZafXt+ZWuGEUaojGKEPgXid3kxC3RipsDV5xsYZ0WEu7H7C3IH b0J1jh+WD330Ksu3FeWq5hnHZJ728iCVRKWftWV0a2XG2Icjh5FZu2/grUWdJx42 zcEx8Yi4MPN85vivY02dFhwx4eFmu39wzwTg31fxkZDyWyCDQPYhxuqxKh3k4zWt TIvN/0AeN7VgxEzHFdeIKvEjHpTleqUtioKpMMS6Mq41oZSdD1yQ/f+ZYq4tjZEj dUEXdfJ4pOsJUQixGqgRYsr1Bw69L12AHRfGVkWlhdlrfTrwT5ulwJkpsP3LXvYR lC3w7X/uvzi8/tfo8IZDnNr0y6WT6ySLEOmcnn+z9mXWf8ej24jEVcpjsTJjb/qX IvxBMUIdUADDS7EABmibjLrJipgHtL+uFcYYXF/cfnf/jmzZetGLrl7655HW5rOE OvftUBZz++kWzwZu+elY =tz2d -----END PGP SIGNATURE----- --Apple-Mail=_42F2F2CD-A6E5-4EAE-990C-9E3A69B31FFC--