Install Theme

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.

iamnearlythere

Learning open source development & mac every day.

Posts tagged php

Dec 8 '10

Roadmap of PHP development - follow it

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

Function Array Dereferencing

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.

E_USER_DEPRECATED

Finally a way to properly mark parts of your API as old:

trigger_error("Use BlaBla::Bla() instead of ".__METHOD__, E_USER_DEPRECATED);

docBlock Parser

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.

Strict type

There are some proposials (about time) for making a method signature like the following valid:

function(int $apples, string $collection_name) {}

C# style getters/setters

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.

Conclusion

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 Tags: php

Nov 4 '10

View comments Tags: php dev

Oct 4 '10

View comments Tags: dev php philosophy

Aug 11 '10

Global code is bad code - PHP’s sessions included

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:

  • product
    • id => 4
    • quantity => 5

Thus, session_destroy() becomes unset($_SESSION['namespace']).

View comments Tags: dev php

Aug 7 '10

View comments Tags: dev php zf

Jul 22 '10

View comments Tags: php

Jul 13 '10

Set enviroment variables in Apache

In .htaccess:

SetEnv APPLICATION_ENV development

In php (from ZF’s bootstrapped setup):
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

View comments Tags: apache dev php server

Jul 6 '10

Requesting new magic method: `__toBoolean()`

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 Tags: dev php