On 20.07.2012, at 4:09, Stas Malyshev wrote:

> Hi!
> 
>> 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.
>> 
>> Example:
>> 
>> <?php $src = 'SoUrCe'; $result = lowered($src); // $result ==
>> 'source', $src == 'SoUrCe' $result = lower($srd);   // $result ==
>> true,     $src = 'source' ?>
>> 
> 
> I'm not sure I understand why. What's wrong with $src = 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 = 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… 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
> 
> 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
> 
> 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, …). I have to call 
str_split explicitly.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to