Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111844 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64856 invoked from network); 4 Sep 2020 18:18:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Sep 2020 18:18:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E2530180088 for ; Fri, 4 Sep 2020 10:23:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 4 Sep 2020 10:23:32 -0700 (PDT) Received: by mail-io1-f52.google.com with SMTP id g128so7862122iof.11 for ; Fri, 04 Sep 2020 10:23:32 -0700 (PDT) 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=DgYUw8JevMamJJwKTGCg+XSXrtO3bsKIFpQqQDQY2zM=; b=GpCZtdJEefU7juYvxFxF5K7Ks9PADpnCpxMkuTpVu+/wu3eKkbG4fRvYVrWtKVVwB+ 3gYw4y8LpsGqLAdoTUo7neiNXOdJWrcKpbR4kKHm6gbaUZKv9qoXxiP46tgn0A+frw9+ 9ltZOT0ZwvGJVHe7PwB6mEqKs6kYw8GlYszc2jfayKSnJgOruhF1Xd7o7nTOEj5lLZg+ tKdouVbE82fEmTeOwhInBbw7qfr8TQ1lvJ42s+l8PVywBQinJyJwbPUiYiLrzgQC4j8O mRXiYysGqRiG6vNxCOeDFFtIiQokgSXxi9cSgfdgJauNsQLr8PeF7UN18aPRnN9T7RkM p/2g== 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=DgYUw8JevMamJJwKTGCg+XSXrtO3bsKIFpQqQDQY2zM=; b=XMbussYg6h85cMDWhCcwJQ5UCHsXL9ZLcgTKQGzSSA4M2CfFVZSbqhBDQs3N+VwuFz CFeLgaff+saEA7DDSOV2sakhM9905ww3q1hgjKqHCQxF/zAmQjHqd5Cy+sAZGyIvCfdE 6FMmhKoKiztE8zggPE6kZdLba6w8P4ETVjdeRog8NDGejNWxfscJhAp4ZnlFXOVB3FC3 wH6WsPyjI9+kp2jQ7lueawM11gp8hZXc2W2eXika/As5BBaqVRCx9ekooGe8rxT9H8ka FtcEC765469TRKpml/FNl+dk/tDjwBSUq4k8+w/OJVf1IJFa93xzrvMROFYaCyKoiQAR qm9w== X-Gm-Message-State: AOAM532ypAgslVjjb73LUz324o5/FWxaw+TFOJwbDoTkl0qvDqtxN3LM 1N74/sf/NXJY1F9aSr3FmuzXZnj55aGMeHQ/KIg= X-Google-Smtp-Source: ABdhPJww5OQ5i6ZUQhi/vaSqP0EdmJ8HKO+V/EEnCHfgMeBxsdWWzBdciNPcyyrhhtGOstLRlpEaagcdaV45wemdRWE= X-Received: by 2002:a6b:e40f:: with SMTP id u15mr8467421iog.132.1599240209358; Fri, 04 Sep 2020 10:23:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 4 Sep 2020 19:23:18 +0200 Message-ID: To: =?UTF-8?B?TWljaGFlbCBWb8WZw63FoWVrIC0gxIxWVVQgRkVM?= Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000096e67d05ae8020b5" Subject: Re: [PHP-DEV] __isset() and null value From: ocramius@gmail.com (Marco Pivetta) --00000000000096e67d05ae8020b5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Heya, On Fri, Sep 4, 2020 at 7:03 PM Michael Vo=C5=99=C3=AD=C5=A1ek - =C4=8CVUT F= EL < vorismi3@fel.cvut.cz> wrote: > isset() returns false for null > > __isset() should return the same, but then if magic property with null > value exists, there is no way to detect it > > Example: https://3v4l.org/GqUsh > > this is currently an limitation of php > > Ideally, we should introduce __exist() which should return true even if > value is null and for BC autoimplement __isset() based on it and __get, > ie. > > function __isset($n) { return $this->__exist($n) && $this->__isset($n) > !=3D=3D null; } > I'd endorse **NOT** checking for property existence on objects that don't have a clearly defined interface/type: that's something for a static analyzer, not (usually) for runtime code. If you still need to do that (anti-patterns such as stuffing things in `stdClass` instances), checking if a property is defined is trivial with reflection: ```php hasProperty('foo'))= ; var_dump((new ReflectionClass(SomethingMagicAndTerriblyUgly::class))->hasProperty('bar'))= ; var_dump((new ReflectionClass(SomethingMagicAndTerriblyUgly::class))->hasProperty('baz'))= ; ``` https://3v4l.org/pVC4j Checking if a **public** property exists at runtime is done via `array_key_exists()`, not via `isset()`: ```php