On Wed Mar 30 09:05 AM, Hannes Landeholm wrote:
>
> var_dump(\substr("foo", 5, 6) == "", (string) false, false == "");
>
> Welcome to PHP. To be honest this criticism pretty much falls in the
> "from person that comes from another language X and is annoyed that
> every little detail isn't exactly the same"-category. Just make your
> own substr() function that uses the behavior you expect if you don't
> like the native version. Although that's bad practice - the best
> solution is to get used to it. And if you have an urge to write about
> your experience with a new language I suggest you do it in a blog
> instead of posting it in the internals mailing list...
I agree with what you're saying but I think you're being a little harsh,
experience with a new language should be something that matters to
internals.
Back to Dan, you're hitting type conversion so not sure I understand "you
always have to deal with this FALSE case":
var_dump(substr('', -1) == '0'); // TRUE
var_dump(substr('', -1) === '0'); // FALSE
Equally to Dan, it doesn't seem like a great way to start the conversation
by saying the "interface is inconsistent and confusing".
There's a perception issue here since you're already used to using language
X,Y,Z.
That said the patch seems to add value to php, why not add str_slice() if it
can solve consistency issues for some users? str_slice likely could be a
faster alternative to substr() in userland parsers.
Also I've seen plenty of bugs caused by type conversion & substr() in
userland
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php