Your web-browser is very outdated, and as such, this website may not display properly. Please consider upgrading to a modern, faster and more secure browser. Click here to do so.
I just discovered an interesting wiki part of php.net, http://wiki.php.net/rfc.
It contains drafts, proposals in an easy-on-the-eyes format. Some of the more interesting topics are
Example:
function a() { return array(1, 2, 3);}
echo a()[0];
Status is listed as “accepted” - finally! This syntax is so handy, the only real alternative seems to be list() which is a bit clunky. Besides, everybody knows this syntax from javascript.
Finally a way to properly mark parts of your API as old:
trigger_error("Use BlaBla::Bla() instead of ".__METHOD__, E_USER_DEPRECATED);
A native parser for docblocks which will probably be a lot faster and also increase awareness and interest of actually documenting code. PHPUnit testcases and frameworks such as Doctrine 2 might gain some speed increase.
There are some proposials (about time) for making a method signature like the following valid:
function(int $apples, string $collection_name) {}
A really usable syntax, instead of __get(), __set() or __call():
class TimePeriod
{
private double seconds;
public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }// The variable "value" holds the incoming value to be "set"
}
}
The proposal then tries to include every possible aspect of this, from the beginning, good idea. Just by reading the discussion on the wiki (never read any mailing lists) I’m already getting tired of it. Too bad.
There exists some really nice discussions in an easy-to-read format. Since there are quite a few proposals already implemented, I probably got hoping for too many new features… In one way, it’s great to see the language improving, in another way: why is it taking so long?
Also, it feels nice to see inspiration coming from other languages (surprisingly javascript stands for quite a few). I wonder if it will become more and more like java, with all the oop/namespacing in the latest patches. (I hope so.) The more global functions we get rid off, the better.
View comments
Nice examples of using value objects/facades instead of primitive constructs, such as arrays.
I will never again write a method like public function getNewsItem(array $options) {}
View comments
Background: I’m thinking of studying for a Zend Certified Engineer (ZCE) exam, for php. A lot of it seems to understand and remember many different types of functions and their parameters (and their order).
This sucks. I made a simple test, realizing that there are well over 5000 globally defined php functions. Many of them may not be bundled, many of them will never appear in the ZCE test; but many of them affect the behavior of coders thinking that <hopefully_this_might_be_a_unique_namespace>_my_function() is a good way to organize code. Maybe, when you’ve reached around 4000 functions, maybe just then you begin to realize that some functions should be grouped in real classes and namespaces.
Who volunteer to help out in the migration process?
View comments
If you rely on sessions in your application, just one call to session_destroy(), like that without any arguments, all your storage is reset. Doesn’t matter if it’s a shopping cart, logged in user’s surfing session, message alert, et cetera.
The only viable solution is to user namespaces like$_SESSION['userSession'] (with loggedInSince as possible key), $_SESSION['shoppingCart'] like such:
Thus, session_destroy() becomes unset($_SESSION['namespace']).
View comments
Migrating to Zend Framework: Legacy Scripts : Chris Abernethy . com
and
View comments
In PHP 5.3.3 __construct() is the only valid name for a constructor.
Edit: oh I was too fast; this change only applies to PHP code within a namespace.
View comments
In .htaccess:
SetEnv APPLICATION_ENV development
In php (from ZF’s bootstrapped setup):// Define application environmentdefined('APPLICATION_ENV')|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
View comments
What if you only want to display your active users in a very simple way? Consider the following:
class User {
public $active = true;
private $_name;
public function __construct($name) {
$this->_name = (string) $name;
}
public function __toBoolean() {
return (bool) $this->active;
}
public function getName() {
return $this->_name;
}
}
$emily = new User('Emily');
$emily->active = false;
$sara = new User('Sara');
$users = array($emily, $sara);
foreach($users as $user) {
if($user) {
echo $user->getName();
}
}
This could provide really convenient shortcuts, like only list unread mails, active users (see example), files in a directory that aren’t . or ..; just about everything!
The __toBoolean() would in some ways be equivalent to the method FilterIterator::accept().
View comments