Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114958 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22391 invoked from network); 18 Jun 2021 15:39:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jun 2021 15:39:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0E8551804A8 for ; Fri, 18 Jun 2021 08:56:46 -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=0.0 required=5.0 tests=BAYES_00,BODY_8BITS, HTML_MESSAGE,KHOP_HELO_FCRDNS,SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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, 18 Jun 2021 08:56:45 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 0CFBF5101324 for ; Fri, 18 Jun 2021 15:56:42 +0000 (UTC) To: php internals Message-ID: <1cee07dc-83aa-a9bd-7219-a7b339c701e1@processus.org> Date: Fri, 18 Jun 2021 17:56:42 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------48B85FDACC6340231CC51BCA" Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Simple support question, about object equality From: pierre-php@processus.org (Pierre) --------------48B85FDACC6340231CC51BCA Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit This code: foo = $foo;     } } $a = new Foo('bar'); $b = new Foo('buzz'); $c = new Foo('bar'); echo "\$a == \$b: "; var_dump($a == $b); echo "\$a == \$c: "; var_dump($a == $c); echo "\$a != \$b: "; var_dump($a != $b); echo "\$a != \$c: "; var_dump($a != $c); echo "\$a === \$b: "; var_dump($a === $b); echo "\$a === \$c: "; var_dump($a === $c); echo "\$a !== \$b: "; var_dump($a !== $b); echo "\$a !== \$c: "; var_dump($a !== $c); ?> Will output:

$a == $b: bool(false)
$a == $c: bool(true)
$a != $b: bool(true)
$a != $c: bool(false)
$a === $b: bool(false)
$a === $c: bool(false)
$a !== $b: bool(true)
$a !== $c: bool(true)

Using: php -v PHP 8.0.7 (cli) (built: Jun  2 2021 04:04:16) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.7, Copyright (c) Zend Technologies     with Zend OPcache v8.0.7, Copyright (c), by Zend Technologies     with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans How is that even possible ?  - I declared strict_types to avoid type coercion  - My data structure is opaque (all properties are private), How does the engine succeeds in comparing my objects ? Isn't it supposed to be always false for == and === and always true for != and !== ? I am missing something ? Regards, -- Pierre --------------48B85FDACC6340231CC51BCA--