Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63789 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28787 invoked from network); 9 Nov 2012 03:51:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Nov 2012 03:51:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:65214] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/83-32758-ECD7C905 for ; Thu, 08 Nov 2012 22:51:43 -0500 Received: by mail-lb0-f170.google.com with SMTP id gm13so2858548lbb.29 for ; Thu, 08 Nov 2012 19:51:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=HMfJDMGvJ4FywuqJrlAz0rRtyJt18/eSV+AoQ8Ed+U0=; b=O6ix7yYFzm/T2qQPSZw+lXUThz6m6rlB4PwgPMmA/+U7v+MiBneQrVJBrVOl9Plq6s krjFrsICCC4w5N/2S6KyL31m6UshMMkua4sXegka3HNBGTneqKvugGHKUusGOhBhEug/ Pw51FVTKgG//CKkZWY1WR0DGSYCko9xc/LGsEz7/5brbHBzlqkGzhvLsBninudL2TjF7 Ke4wSz/LLi/4KcXNephosb0fp01gRf0mb4IO632uAeN5yS7KfHvChhpc4vYp37O6R154 V/EB9ALfxtjlgf3g6U40G2HJXJZxPM18i4Z9DwsbqAUmT2BaZeV0YJecb+9FSa2+nHrb Y71Q== MIME-Version: 1.0 Received: by 10.152.105.44 with SMTP id gj12mr9603375lab.19.1352433098724; Thu, 08 Nov 2012 19:51:38 -0800 (PST) Received: by 10.112.24.37 with HTTP; Thu, 8 Nov 2012 19:51:38 -0800 (PST) In-Reply-To: References: Date: Thu, 8 Nov 2012 22:51:38 -0500 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Object comparison From: theanomaly.is@gmail.com (Sherif Ramadan) On Thu, Nov 8, 2012 at 7:07 PM, Sara Golemon wrote: > From: http://php.net/manual/en/language.operators.comparison.php > > An object compared to anything which is not a bool, null, or object > should result in the object appearing to be greater than the other > operand. For example: > > $a = new stdClass(); > $b = new stdClass(); > > var_dump(null < $a); > var_dump(false < $a); > var_dump(true == $a); > var_dump($a == $b); > var_dump(0 < $a); > var_dump(1 < $a); // false > var_dump(2 < $a); // false > var_dump("foo" < $a); > var_dump("2" < $a); > var_dump(tmpfile() < $a); > > Based on docs, I expect all nine of these to yield true, however in > practice, the two marked "false" come out as false because the RHS > object is converted to an integer (1), contrary to the docs. > > Doc bug? Or code bug? I'm inclined to call it a code bug, but wanted > others' thoughts. > Hi Sara, I believe the documentation is failing us here. From what I see the docs are pretty lacking in what should be expected in terms of object comparison. For example, the page at http://php.net/types.comparisons doesn't even include objects in the comparison table. Of course by looking at the "Comparison with Various Types" table at http://php.net/language.operators.comparison one gets the impression that the "Operand 1" and "Operand 2" columns are to signify LVALUE and RVALUE operands, respectively. Obviously this isn't the case and the documentation just fails us here. var_dump(new stdclass < 1, newstdcalss > 1, 1 < new stdclass, 1 > new stdclass); // false, false, false, false Clearly there are cases when the object can be neither less-than nor greater-than an operand in a comparison. The statement "object is always greater" in that table is misleading and doesn't tell us the whole truth. For example, class foo { public function __toString() { return ''; } } var_dump(new foo < '', new foo > '', '' < new foo, '' > new foo); // false, false, false, false Obviously there are more complex cases where the object may not pan out to be greater than a non-object type that the documentation fails to address. > -Sara > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >