News for hackers. Stuff that matters.
Re:PHP Hacking aka trying to push PHP internals forwards by jcoby on Friday June 10, 2011 @11:15AM (#2641136)
Many of the problems and annoyances with PHP could be fixed while keeping backwards compatibility.

Just a short list I can think of now:

- Short array syntax. Completely optional but would clean up the language quite a bit. This has been proposed several times and shot down each for no real good reason.

- Promote complex primitives into objects. With the proper interfaces it wouldn't break any old code. Once this is done, deprecate the myriad of str* and array* functions in favor of the object methods. This also cleans up the "what order do i pass in the args" problem that so many people cite.

- Named parameters. Gets rid of passing in default params or an array blob for functions/methods that take lots of optional params. It also opens up the way for DSLs.

- Replace PEAR with something better. The quality of PEAR modules is really low and PEAR always seems to be broken one way or another.

- Add a list and hash type. PHP's array is very slow for some cases, and sometimes you need to enforce the datatype you're working with.

- Use exceptions for errors. Could be a runtime flag to prevent breaking things. It's incredibly easy to write bad code because PHP make it easy to ignore problems. Things like functions that connect to the db or trying to retrieve data from a stream don't throw exceptions on error.

Re:PHP Hacking aka trying to push PHP internals forwards by adaml_623 on Friday June 10, 2011 @11:46AM (#2641271)
Well to be honest if you deprecate the str* and array* functions you are pretty much breaking backwards compatibility.

I'm not saying it wouldn't be a good thing but those functions are one of the defining features of PHP imho

Re:PHP Hacking aka trying to push PHP internals forwards by josegonzalez on Friday June 10, 2011 @11:51AM (#2641289)
Deprecation is not the same thing as removal.
Re:PHP Hacking aka trying to push PHP internals forwards by abarrett on Friday June 10, 2011 @06:09PM (#2642608)
Regarding your first point: it seems short syntax for arrays may well make it into PHP 5.4.

http://www.reddit.com/r/PHP/comments/hw8da/php_fork_based_on...

Re:PHP Hacking aka trying to push PHP internals forwards by wvenable on Friday June 10, 2011 @12:14PM (#2641376)
PHP already provides a mechanism to replace errors with exceptions (set_error_handler() and the ErrorException exception type). I do this on all my projects.
Re:PHP Hacking aka trying to push PHP internals forwards by jcoby on Friday June 10, 2011 @12:27PM (#2641428)
I'm aware of that method. It's not an ideal approach IMO.

Specific errors should throw specific exceptions. That way I can handle the ones I know how to handle and let the others bubble up and either completely break the app to be logged and fixed later or get handled correctly somewhere else. With ErrorException, you have to look at the contents of the error message to see if it's an error you can handle or need to rethrow.

Re:PHP Hacking aka trying to push PHP internals forwards by wvenable on Friday June 10, 2011 @12:53PM (#2641527)
If something in PHP triggers an error, there is very little to recover from. It's either a developer error or an unrecoverable problem (a file expected to exist was not found, network is down, etc). In any of my projects, I've never needed to recover from PHP ErrorException.