Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91179 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49423 invoked from network); 10 Feb 2016 06:52:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2016 06:52:13 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.171 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.160.171 mail-yk0-f171.google.com Received: from [209.85.160.171] ([209.85.160.171:34460] helo=mail-yk0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/42-12072-C1EDAB65 for ; Wed, 10 Feb 2016 01:52:12 -0500 Received: by mail-yk0-f171.google.com with SMTP id u9so4280909ykd.1 for ; Tue, 09 Feb 2016 22:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=VZfpbn6sE7p4zMZAcGzAlpUCGGsh5ea3MWEia1QYHls=; b=sReCNy+54KMdj5345xOOyZhvoWf1JEUBer7tIS7pAGuokYoOFbG0CT2UM6PQPr4kIn 9Q288l2JUelgS9yE9ypSf+egTbPUPrFd3T/hFPAxYUwddoIST+/vG/3e8gsmeBT054GP UIVH341hTI1CxL9DYwZV80FzZxSvOqxVqmwAm8tuPc7axyhNOmP/8b4joP8hX3bgDvcW mF6VGMPYzem2JYLzfHIzYTkGAOOYBovSNWC9mvVMciW9cI7cwJZFdXpR73jG40L2vIDg s6lqhXeSAiIUqqkL46q1B3Zbl77Lmm0th4UOjvoUKcg8KB2zlNkRe8quTqaUMEkpKK7w /5Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=VZfpbn6sE7p4zMZAcGzAlpUCGGsh5ea3MWEia1QYHls=; b=gLlpsAHmFUuSogYf+pZsXBSlizxMspmll4/y9RLg2chSOS5PCEEHct+2HZO6C04nCK GulN98gI+jO5hcH+hxG3twWeAQZ112HCUL3qHwVY/9d9uVsOCQ+H4cUsltk6KSdvqaSw zjvEX2w9zp0KTmMEe/8tyU0+s8ce92WFafWlbFx+mlQGqea7POlo3VX3UPvpRiyl05Aj G5v5p5k66xi0XzNNUabGJUbKWfAcRYUraAMRW2sLhkgJcFBcB3UOdLH2nstfekFO/uKE iDYYk8RQefRN/n6UhNjwACQ+boQefwMA9ScLF1HiaAPxsGvTzuZaDLjXZra2qP/mOF19 MYpA== X-Gm-Message-State: AG10YOTBekOqr2AnHuTna9eGphptohVmdw5DaeQkKRHufwbC5ejN6evATV1Uf+gr45OFpruvK1h11v9Tdm2Krw== X-Received: by 10.37.231.68 with SMTP id e65mr20101654ybh.130.1455087129969; Tue, 09 Feb 2016 22:52:09 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.129.109.22 with HTTP; Tue, 9 Feb 2016 22:51:30 -0800 (PST) In-Reply-To: <56B8AFC1.7040100@php.net> References: <56A3A01F.1020500@php.net> <56AE8735.4070901@gmail.com> <56AFC8CC.6040201@gmail.com> <56B6680F.6070804@gmail.com> <56B8AFC1.7040100@php.net> Date: Wed, 10 Feb 2016 15:51:30 +0900 X-Google-Sender-Auth: PzcGY-DcrrH9oibaRQ9iVUsl3sU Message-ID: To: =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= Cc: Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Generalize support of negative string offsets From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi Francois, On Tue, Feb 9, 2016 at 12:09 AM, Fran=C3=A7ois Laupretre = wrote: > Slightly off-topic but, as I was looking for the way to add support for > '$str[]=3D' assignments, I found something strange. > > Just for curiosity, does someone know a reason for this : > > $str =3D "abc"; > $str[1]=3D"z"; > var_dump($str); // -> string(3) "zbc" -> Expected > > $str =3D ""; // Empty string > $str[1]=3D"z"; > var_dump($str); // -> array(1) { [0]=3D>string(1) "z" } -> !!! > > The input string is converted to an array if it is empty. This becomes st= ill > funnier with : > > $str=3D"a"; > $str[] =3D 'z'; // -> Fatal error : [] operator not supported for strings > > $str=3D""; > $str[] =3D 'z'; // -> OK -> $str gets array(1) { [0]=3D>string(1) "z" } > > Thoughts ? PHP should raise E_WARNING errors for them as other scalar, IMO. php > $v=3D1; php > $v[] =3D 'z'; PHP Warning: Cannot use a scalar value as an array in php shell code on li= ne 1 php > $v=3DTRUE; php > $v[] =3D 'z'; PHP Warning: Cannot use a scalar value as an array in php shell code on li= ne 1 It seems "" is treated just like NULL/FALSE php > $v=3Dnull; php > $v[] =3D 'z'; php > var_dump($v); array(1) { [0]=3D> string(1) "z" } php > $v=3Dfalse; php > $v[] =3D 'z'; php > var_dump($v); array(1) { [0]=3D> string(1) "z" } NULL may become any type of variables, but empty string and FALSE should behave like 'scalar' variable. This could be largest BC of this RFC, but it's consistent with int variable. php > $v=3D0; php > $v[] =3D 'z'; Warning: Cannot use a scalar value as an array in php shell code on line 1 BTW, what would happen with $var{} =3D 'str'? php > $v=3D'abc'; php > $v{} =3D 'str'; PHP Parse error: syntax error, unexpected '}' in php shell code on line 1 Currently, it's not allowed. It may behave like $v .=3D 'str'. I'm not sure if PHP should. It looks consistent syntax with array. i.e. "$v[] =3D $val" adds $val as last element. Behavior regarding array. (a bit off topic, but error level should match with new string '{}' errors.) php > error_reporting(-1); php > $v=3Darray(); php > $v .=3D 'abc'; Notice: Array to string conversion in php shell code on line 1 php > var_dump($v); string(8) "Arrayabc" This insane string assignment raises E_NOTICE. PHP may be better to raise E_WARNING for this kind of invalid assignments just like php > $v=3D1; php > $v[] =3D 'z'; PHP Warning: Cannot use a scalar value as an array in php shell code on li= ne Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net