Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16400 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4740 invoked by uid 1010); 6 Jun 2005 06:39:14 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 4725 invoked from network); 6 Jun 2005 06:39:14 -0000 Received: from unknown (HELO marcus-boerger.de) (127.0.0.1) by localhost with SMTP; 6 Jun 2005 06:39:14 -0000 X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from ([81.169.182.136:37241] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 55/B2-54652-19FE3A24 for ; Mon, 06 Jun 2005 02:39:14 -0400 Received: from baumbart.mbo (dsl-082-083-239-049.arcor-ip.net [82.83.239.49]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id 8C9AB35C278; Mon, 6 Jun 2005 08:51:35 +0200 (CEST) Date: Mon, 6 Jun 2005 08:37:13 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1558647963.20050606083713@marcus-boerger.de> To: Derick Rethans Cc: Johannes Schlueter , internals@lists.php.net In-Reply-To: References: <200506052048.58029.johannes@php.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] incrementing boolean values From: mail@marcus-boerger.de (Marcus Boerger) Hello Derick, Sunday, June 5, 2005, 10:27:51 PM, you wrote: > On Sun, 5 Jun 2005, Johannes Schlueter wrote: >> Hi, >> >> PHP is a weak-typed language which casts in the background as required - at >> least most of the time. I recently found an exception which bugged me: >> >> $a = false; >> $a++; >> >> Here $a isn't casted to int or "incremented" to true but the incrementing has >> no effect. By checking zend_operators.c I saw that booleans had no explicit >> incrementing rule but uses just the default in the relevant switch. >> >> Looking a bit deeper it got quite interesting: NULL++ gives as result the >> integer one. This is fine for incrementing undefined variables but imho >> inconsistent with the behavior of false. NULL-- evaluates to NULL similar to >> false but different from NULL++. >> >> All this makes using PHP harder than needed. At least I spent quite some time >> finding that my variable was set to false instead of 0 (or NULL). >> >> I wrote the attached patch which allows in-/decrementing of simple types by >> casting bools and NULL to long. Yes, it would be a BC break but I don't think >> someone relies on false++ being false and it would make life simpler. >> >> Comments? > I did this a year or so ago, and after discussing with Andi we decided > not to promote types in this case. Not promoting types would mean adding false++, and true-- doesn't it? And again not doing this complicaates php needlessly. For example the two snippets below are different, tell me why: 1) if (($p=strpos(...)+1) > 0) ... 2) $p = strpos(...); $p++; if ($p > 0) ... Sidenote: Why is the following a parser error: if (($p=strpos(...))++ > 0) ... -- Best regards, Marcus mailto:mail@marcus-boerger.de