Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3386 invoked from network); 20 Jul 2012 09:03:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jul 2012 09:03:38 -0000 Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; 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: indeyets@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:60798] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/9B-18983-9EE19005 for ; Fri, 20 Jul 2012 05:03:37 -0400 Received: by lbgc1 with SMTP id c1so5380971lbg.29 for ; Fri, 20 Jul 2012 02:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to:x-mailer; bh=TtXuM8wvJ0WszLhCSlzOw6jX88qHnX38r0aoRqFWI1I=; b=itUcxoxcSouaQUF63wi788XNhxEB7w6IC+mTLgcVywpfEAg73VMbedEW5p9Yrf1JxN zypZNG5OAW6LblxeVgK4vLoihpQfNaRLavwVFdHrAWSMfmQqZF0fG/VB6jXvAZhVBcj2 qFz/v+rECz8plwMw15TDmemXcO8i/php3HN7P1HN8KSzUPQSmSnQsnQpg+KwcQqx41r4 sdx8LtxD+EhwbdKk8zh4BUDOFtf3Y52tzg1KTPU7gqOU7nQGxFDPY7Ttlk3BhNwpP8P+ b7ah18oUGhyXOixL7K1m6NMOmfAgWAp6pKOz7Nhqci4dmpT91VkuArZ9/fFfbamGLvZg nzuw== Received: by 10.152.102.137 with SMTP id fo9mr5391987lab.35.1342775014298; Fri, 20 Jul 2012 02:03:34 -0700 (PDT) Received: from [10.0.1.7] ([93.185.190.227]) by mx.google.com with ESMTPS id sm7sm4368838lab.5.2012.07.20.02.03.31 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 Jul 2012 02:03:32 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: multipart/signed; boundary="Apple-Mail=_E67AA4AD-D331-4B7E-8FDC-0CCC392CA38A"; protocol="application/pgp-signature"; micalg=pgp-sha1 In-Reply-To: <5008A1AE.9090404@sugarcrm.com> Date: Fri, 20 Jul 2012 13:03:32 +0400 Cc: internals internals Message-ID: References: <64223D01-8F4C-4B65-AD6C-5C425EC0EA68@gmail.com> <5008A1AE.9090404@sugarcrm.com> To: Stas Malyshev X-Mailer: Apple Mail (2.1278) Subject: Re: [PHP-DEV] Regarding PHP6, string/array APIs From: indeyets@gmail.com (Alexey Zakhlestin) --Apple-Mail=_E67AA4AD-D331-4B7E-8FDC-0CCC392CA38A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On 20.07.2012, at 4:09, Stas Malyshev wrote: > Hi! >=20 >> 2. It would be really useful to have 2 versions of each function: one >> which mutates the variable and one which returns the new variable. >>=20 >> Example: >>=20 >> > 'source', $src =3D=3D 'SoUrCe' $result =3D lower($srd); // $result = =3D=3D >> true, $src =3D 'source' ?> >>=20 >=20 > I'm not sure I understand why. What's wrong with $src =3D = lowered($src);? That's just convenience. matter of readability. lower() can be implemented in userland and if we had "standard" userland = library that would be a good place for it :) function lower(&$str) { $str =3D lowered($str); } > Also, when lower() returns not true? If there's a legitimate situation > when it must return not true (I can't think of any, but maybe for more > complex functions there is) what lowered() is supposed to do in the = same > situation? If there's none, why bother returning true? As you said, it might be needed in more complex functions and it makes = sense to return true just for consistency. Other option is to (implicitly) return null and use exceptions. And I, personally, would prefer exceptions ;) >> 3. Speaking of implementation=85 Functions, which return slice of >> string/array could be made to reference the same memory-areas as the >> source strings/arrays. That is until the first modification, of >> course. Kinda advanced copy-on-write semantics. I know something like >> that is implemented in D http://dlang.org/d-array-article.html and >> Go >=20 > Strings are not modified in PHP (IS_STRING zvals can be modified but = the > actual string buffers aren't) so there's no actual "write" and thus no > copy needed. But having this would require separate refcounting on > string values, which may be a bit complicated to do. much worse than that. refcounting on string-slices! >> 4. casting between strings and arrays of characters would be a great >> thing to have too. this way, useful array-oriented functions could be >> applied to strings >=20 > We already have it, it's str_split(). I know. But that is not "casting". I can not pass string to the function = which expects array (thinking about array_map, array_filter, =85). I = have to call str_split explicitly. --Apple-Mail=_E67AA4AD-D331-4B7E-8FDC-0CCC392CA38A Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) iQEcBAEBAgAGBQJQCR7kAAoJEM8kLGy4PJ4JMFgIAIccwIi67sqK1RZKm/y5H5bk vXLd49AIxRp0IWspAF53oovl7NUM6Rx+c5Iex8aTaTW+ZNpltybV89UkBqoLCOmk A8B7u0s4aiRtSiCVyeC2IwmsphDJM64ZdTZN04vN6RJ2vaD1tQV5bGdsuNv8JiOj akjC2sbJbDCfxqWesT6lTHbI3sReSEqpaVwQWcX5bgs7L5LE/lE0DWRG/wDNDjMC IVl2us7Tpj81LxekiXJ/dLEYBPuveQQpcuAU5c5gwaKKARGKp6LDivWWV+198pz8 WDda8gBSopz7kKA+uRwL2Ju1oNqBiL0IdhijZwCswux/eFXxAjYdj56B9ymQagA= =U9a8 -----END PGP SIGNATURE----- --Apple-Mail=_E67AA4AD-D331-4B7E-8FDC-0CCC392CA38A--