Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106641 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34327 invoked from network); 18 Aug 2019 12:45:43 -0000 Received: from unknown (HELO mail-oi1-f176.google.com) (209.85.167.176) by pb1.pair.com with SMTP; 18 Aug 2019 12:45:43 -0000 Received: by mail-oi1-f176.google.com with SMTP id g7so7773836oia.8 for ; Sun, 18 Aug 2019 03:15:20 -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=4PQTGw10Z2s9m0wc/F9ee4mfNncjDc4r/+AhCgh40xU=; b=RFGWdmK3cUeVlRk9bJeRaCYpkMVymANplCyYMw0gIN1LmV3ytzw0sBkf8znQOMT+gl qdilid/OIlZ8auc8kVWlZCcRKV6zrrvBlRe9PZyzhEjdUBSctN/uK3Gs5P4PEa+Fy4+s DIFvtMZJi31xyzoTMBRHklFlXJ6/wVKEw2lmanNSL5zvisY5eD+TDPexdYqusTNHvGyv GJqkPqD2jJOPJJa9o95/HSAMwgxmyvYNeb/brnccEr4/QeEo3dAsmd5QmDPE69udx0YA OxX2B7OffgHu5NS5kU+WLtnbUr0wi+lQpRYW1k/eo6OlBJNWwqOzvkq/AWPzcHPilzmc ZuNw== 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=4PQTGw10Z2s9m0wc/F9ee4mfNncjDc4r/+AhCgh40xU=; b=aa3b+tLQPVVQkoqUCrvyze7fvh3/c0zYEnoZ4YmSPhW/7KCj8qCeHbp7HFc/LUTYhU pk/1e4WYxNeyXrg+HcjQZMZFRsBXkWsjuWH7WOet9RWJTgRx10Z6NuMab69IB9JfDkOG Hoei2Z4OvOaWsw99SNqnBsUQmjrtjhv4R3QMOSQ5meLpSI3+PmeH58oSXNk3CXCVHMC7 D2OS4EXxQdV7kdFlTSSAGP7qdqQpBmZ1/B8dyauqA8wD5kjUaeoaEUM/l4dOAGxa7M7t M7hYmFWcqDjtfHZF6VHoJn8YNjuYEumT4u5wlSrS0nCToAo9GaiBuM+ktdPGv7inZKsn Zw1w== X-Gm-Message-State: APjAAAUgK/mLby8sR/tUe7L0p5Jp1YmQIpTkvSaNUakbiS2LwyHugi8P GOOvXJT6TqKm7P+cwF3tl8ZCfDn8iTeALAspGYU= X-Google-Smtp-Source: APXvYqwnDuGJEQKhKdhcImkLkfipMDPfKmo4P54NT3cFW3Wir240VjJr7D2fwpOyD/4ef3modW4ZVZye+SyE6MuIp44= X-Received: by 2002:a05:6808:34c:: with SMTP id j12mr10564212oie.142.1566123319728; Sun, 18 Aug 2019 03:15:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 18 Aug 2019 12:14:52 +0200 Message-ID: To: Benjamin Morel Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000259d980590618094" Subject: Re: [PHP-DEV] get_class_vars() and typed properties From: nicolas.grekas@gmail.com (Nicolas Grekas) --000000000000259d980590618094 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le dim. 18 ao=C3=BBt 2019 =C3=A0 11:59, Benjamin Morel a =C3=A9crit : > Hi Internals, I just noticed the following behaviour: > > class A { > public int $a; > public ?int $b; > public ?int $c =3D null; > } > > $a =3D new A; > > var_export(get_object_vars($a)); > var_export(get_class_vars('A')); > > Result: > > array ( > 'c' =3D> NULL, > ) > array ( > 'a' =3D> NULL, > 'b' =3D> NULL, > 'c' =3D> NULL, > ) > > Is this discrepancy expected? IMO get_object_vars() does the right thing > and does not include uninitialized properties in the result array. > > OTOH, get_class_vars() returns null when the property is uninitialized, > which I think is confusing (especially when null is not a valid value for > the property), and I feel like this does not respect the documented > contract: "get_class_vars =E2=80=94 Get the default properties of the cla= ss" when > null is *not* the default value. > > I did not file a bug yet as I wanted to gather some feedback first. > Thank you. > > =E2=80=94 Benjamin > See https://bugs.php.net/78319 get_class_var() does the most useful thing, thus the correct one to me and the use cases I have. Nicolas > --000000000000259d980590618094--