Earlier quoted context omitted.
> cough Unicode anyone? Why are you coughing about unicode? It works just fine as long as you use utf-8, and there is little reason not to.
What he meant to say was, "I wish PHP has a 'string' type instead of octet buffers".
Short array syntax finally in PHP 5.4
71–80 of 80 posts
Re: Short array syntax finally in PHP 5.4
#72Earlier quoted context omitted.
The best step forward for PHP, in my opinion, would be to deprecate all of those fake-namespaced functions, and start treating instances of built-in types as objects. This would also be the chance to fix all the 'needle/haystack, haystack/needle?' type inconsistencies. The older functions could still exist for backwards compatibility, but people who want to write clean OO code could use the new style. $anArray->map(f…
Loose typing plus strong OO for basic types is a pretty horrifying cmbination, IMO. What happens if you call $aString->pos() when PHP decides that $aString can be an int because it happens to be holding a string that's composed of numbers?
Re: Short array syntax finally in PHP 5.4
#73My big complaint about arrays wasn't declaring them. It was the endless array functions you have to use afterwards. array_push array_pop array_slice array_shift array_unshift array_map array_key_exists It kind of feels like they missed the point, saving 5 characters when you declare the array once, ignoring all of the other operations you do afterwards. And this RFC, simple as it is, took 3.5 years to come to fruitio…
While I would love them to bring the array functions more into line with other OO langauges, the entire language is not structured around that concept, so you would be in essence writing a whole new language. Because almost all the modern PHP frameworks use arrays to pass data, the short-array syntax makes viewing multi-dimensional arrays much easier, and thus will hopefully result in less bugs. Example: $this->link(…
After having to use PHP for a while, it's no coincidence that these days I am using a whole new language.
Re: Short array syntax finally in PHP 5.4
#74My complaint about arrays in PHP is warnings for reading a array member that may not exist, such as when reading a form input that might not be there. $foo = $_POST["foo"]; Undefined array key! Oh, no! Tragedy! A crime has been committed! Are you kidding? Just set $foo to undefined and let me deal with the consequences, please?
Re: Short array syntax finally in PHP 5.4
#75Still strikes me as a useless bit of syntactic sugar. Is it really that much work to write array('foo' => 'bar')? As far as I can tell, writing ['foo' => 'bar'] isn't that much shorter in the first place. sigh Can the PHP devs focus on the real problems now? cough Unicode anyone? Ridiculously inconsistent naming of string and array functions? The woefully incomplete and useless STL? The lack of OO in arrays and strin…
Hey, I've been complaining about PHP's lack of Unicode support forever. Every time I do, though, an apologist comes out of the woodwork to tell me about the mb_*() functions. Apparently the PHP community is quite comfortable not caring about non-ASCII characters.
Andrei Zmievski has been giving this presentation on what happened to Unicode in PHP. A huge amount of work went into making it happen but it eventually could not continue due to several reasons, including design decisions, lack of contributors & interest in the project.
Re: Short array syntax finally in PHP 5.4
#76My complaint about arrays in PHP is warnings for reading a array member that may not exist, such as when reading a form input that might not be there. $foo = $_POST["foo"]; Undefined array key! Oh, no! Tragedy! A crime has been committed! Are you kidding? Just set $foo to undefined and let me deal with the consequences, please?
You really wouldn't like Python or even stricter languages such as Scala or java, then. In Python, an attempt to access a nonexistent dictionary key will throw an exception which halts execution if not caught. (similar to calling a nonexistent method or function in PHP, but since PHP doesn't have a well-thought out exception system/std. lib as Python does, you can't catch anything in that situation in PHP).
$val = array_key_exists('key', $dict) ? $dict['key'] : NULL;
Being able to say "I expect a potentially nil value (and am okay with that)" via get() rather than array index is both semantically useful, and far more beautiful than the PHP equivalent.Re: Short array syntax finally in PHP 5.4
#77Earlier quoted context omitted.
You really wouldn't like Python or even stricter languages such as Scala or java, then. In Python, an attempt to access a nonexistent dictionary key will throw an exception which halts execution if not caught. (similar to calling a nonexistent method or function in PHP, but since PHP doesn't have a well-thought out exception system/std. lib as Python does, you can't catch anything in that situation in PHP).
In Python, if you're expecting a potentially missing key, you can just use dict.get('key') rather than dict['key']. The equivalent in PHP would be something like: $val = array_key_exists('key', $dict) ? $dict['key'] : NULL; Being able to say "I expect a potentially nil value (and am okay with that)" via get() rather than array index is both semantically useful, and far more beautiful than the PHP equivalent.
Re: Short array syntax finally in PHP 5.4
#78Re: Short array syntax finally in PHP 5.4
#79My big complaint about arrays wasn't declaring them. It was the endless array functions you have to use afterwards. array_push array_pop array_slice array_shift array_unshift array_map array_key_exists It kind of feels like they missed the point, saving 5 characters when you declare the array once, ignoring all of the other operations you do afterwards. And this RFC, simple as it is, took 3.5 years to come to fruitio…
Re: Short array syntax finally in PHP 5.4
#80Earlier quoted context omitted.
You really wouldn't like Python or even stricter languages such as Scala or java, then. In Python, an attempt to access a nonexistent dictionary key will throw an exception which halts execution if not caught. (similar to calling a nonexistent method or function in PHP, but since PHP doesn't have a well-thought out exception system/std. lib as Python does, you can't catch anything in that situation in PHP).
In Python, if you're expecting a potentially missing key, you can just use dict.get('key') rather than dict['key']. The equivalent in PHP would be something like: $val = array_key_exists('key', $dict) ? $dict['key'] : NULL; Being able to say "I expect a potentially nil value (and am okay with that)" via get() rather than array index is both semantically useful, and far more beautiful than the PHP equivalent.
Python's dict.get is a bit like the getOrElse found in Scala. It's quite handy and can be seen as advanced conceptually.
I actually added some code like that to a recent post about PHP here: http://news.ycombinator.com/item?id=2771304