Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105200 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25916 invoked from network); 10 Apr 2019 12:40:36 -0000 Received: from unknown (HELO mail-it1-f169.google.com) (209.85.166.169) by pb1.pair.com with SMTP; 10 Apr 2019 12:40:36 -0000 Received: by mail-it1-f169.google.com with SMTP id y204so2331572itf.3 for ; Wed, 10 Apr 2019 02:37:42 -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=Z7TgRMGlrgR8DqZvkXy6bfXFzWKJ+ql/u5KNnzZjt4I=; b=Y3hwu4Ay8065GRyCU98joKy2RDQTxWeo5aTRIE7LDDk/lP2+PNLcS8WmLl+XNNjDkv iTTPCVHXFNv0JfZ/yUjJmYA+XteH2bbDYHb+9JL3WtWjnzkinUgNx4e7zkSr7ErU/BMk zghSAjsgJghVhdZXD/Ho+yiVownTDQQtOdQHGa+wP3Kk52RYmVzBK+8lPKaRDo5un0aq BnMX0dfpXNEZSQpT5Iyirr7wVc5sLRz3hBsVSEJymZ9hmrjzn8my5zrtZfXpg4eEyAn6 +aTvmPEGnxwEdY8bzacMAig+0F6Nw6quUsrck3nlSzRHP2qfLP1Zdu/ghQhZpVyZCExo m09g== 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=Z7TgRMGlrgR8DqZvkXy6bfXFzWKJ+ql/u5KNnzZjt4I=; b=NtwuSGvWWombEC4oIugh2LOJlV/ugXIEzSDNECtvYmNVPzLJC4yR9d3mARrtfZ/saB adaPb4D+TWscbysdC3bu47HVUZSAYhejLrBSpVrv/CG0yGEImnKcLJ7MnbVP2cdsEEJm MvVftlRVZCRsnJvh3w9v2hGzzuxGcRemJgI6Ez9fhr48ZBrQ+26/JxIW83AOL0PF4WL1 w1srLaM0dzak1ECj5/u8SG6fj8FyPLt29SLMRuwr0RLxtfccWyrjcU0Vo0PKd5kfNjh9 42rcPwysIBWrTIg/05KO11adb05dYneDtbJBGg0Gixt6/9041G1vW23A/12EmJJHKzXz /CGg== X-Gm-Message-State: APjAAAUNClCZWE4bu+uyvmikE13VScj78lG6l2Z4NgQ/BkrerBkUzlY+ hq29hiMhN998B4XxWtPMQXpJflwasJ4MC78R9dU= X-Google-Smtp-Source: APXvYqzw1P230LHJlOc2li4v2hrpG5UzhuA7dC0gaaguXhy7HATcKA0a/W8D3fqn9rCdBDzGknY9z3415yb+F2WzY68= X-Received: by 2002:a02:c007:: with SMTP id y7mr30658080jai.1.1554889061984; Wed, 10 Apr 2019 02:37:41 -0700 (PDT) MIME-Version: 1.0 References: <40683e93-f8e9-5a8c-9646-31c73c99396f@fischer.name> <5ca53eb4.1c69fb81.e223b.922eSMTPIN_ADDED_MISSING@mx.google.com> <5cadaa32.1c69fb81.95a2d.a393SMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <5cadaa32.1c69fb81.95a2d.a393SMTPIN_ADDED_MISSING@mx.google.com> Date: Wed, 10 Apr 2019 11:37:30 +0200 Message-ID: To: Mark Randall Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000346deb058629d2bd" Subject: Re: [PHP-DEV] [RFC] Permit trailing whitespace in numeric strings From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000346deb058629d2bd Content-Type: text/plain; charset="UTF-8" > > I'm somewhat split on this one. > On the one hand, if I make an explicit cast, my intention is clear, make > the best attempt to convert this string into a number. Trimming > whitespace would be a natural consequence of that. > On the other hand, I'm a stickler for consistency. > On the balance of things, I would most certainly like to see leading and > trailing whitespace render a string ineligible to be implicitly > converted, but I'd be satisfied with (int)" 123 " converting without error. > I'm all for consistency between `(int)` casting, `(int $x)` function parameter and `: int` return type, *even* if this justifies allowing leading and trailing whitespace around numbers, if this helps adoption. As long as we no longer allow `(int) "abc"` to return `0`, I'm game. On the topic of errorsfor explicit casts I'd be more inclined to also > introduce (?int) and in the event the value cannot be converted, return > null. If (?int) casting is introduced, I would only return null if the original value is null. Otherwise, throw an TypeError. This is the only consistent behaviour with scalar type hints and return types. Ben --000000000000346deb058629d2bd--