Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16389 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46547 invoked by uid 1010); 5 Jun 2005 20:27:58 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 46531 invoked from network); 5 Jun 2005 20:27:58 -0000 Received: from unknown (HELO php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2005 20:27:58 -0000 X-Host-Fingerprint: 82.94.239.5 unknown Linux 2.5 (sometimes 2.4) (4) Received: from ([82.94.239.5:52376] helo=jdi.jdi-ict.nl) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 06/97-56751-C4063A24 for ; Sun, 05 Jun 2005 16:27:56 -0400 Received: from localhost (localhost [127.0.0.1]) by jdi.jdi-ict.nl (8.12.11/8.12.11) with ESMTP id j55KXWFb019803 for ; Sun, 5 Jun 2005 22:33:32 +0200 Received: from localhost (localhost [127.0.0.1]) by jdi.jdi-ict.nl (8.12.11/8.12.11) with ESMTP id j55KXVHe019784; Sun, 5 Jun 2005 22:33:31 +0200 Date: Sun, 5 Jun 2005 22:27:51 +0200 (CEST) X-X-Sender: derick@localhost To: Johannes Schlueter cc: internals@lists.php.net In-Reply-To: <200506052048.58029.johannes@php.net> Message-ID: References: <200506052048.58029.johannes@php.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at jci-ict.nl Subject: Re: [PHP-DEV] incrementing boolean values From: derick@php.net (Derick Rethans) 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. Derick -- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org