What is new in PHP 5.3 – part 4: __callStatic, OpenID support, user.ini, XSLT profiling and more

Date November 20, 2007

We are already familiar with namespaces, late static binding and mysqlnd but PHP 5.3 has a lot more cool features. We can find some information about the features of the upcoming PHP version from Johannes Schlüter’s (the release manager of PHP 5.3) blog entry and from the PHP Release Management Wiki. Some of the features are interesting only for internals, but there are a lot of great ones for end users too: __callStatic, dynamic static call, OpenID support, improved ini handling, XSLT profiling, SQLite 3 support and more.

__callStatic()

Probably you are familiar with PHP’s magic methods. PHP 5.3 introduces a new magic method: __callStatic, which is very similar to __call but it is for static calls. It is cool, we are waiting for the __get, __set etc. counterparts. :)

1
2
3
4
5
6
7
8
9
10
11
<?php

Foo::bar();
class Foo
{
    static function __callStatic($method, $arguments)
    {
        // $mathod == &qout;bar&qout;...
    }
}
?>

Dynamic static calls

I think variable variables are one of the most useful things in PHP. In PHP 5.3 there is a new possibility on this area, the following code is possible:

1
2
3
4
5
6
7
8
9
<?php
$class = 'bar';
$class::method();
$class::$member;
$class::CONST;

$namespace = 'foo';
$namespace::$class::method();
?>

You can find here a useful example from Etienne Kneuss, who implemented the patch for this functionality.

Improved ini handling

Jani Taskinen created a patch providing improved ini handling. We can get some insight of how it will be working from the commit message:

  • Added “.htaccess” style user-defined php.ini files support for CGI/FastCGI.
  • Added support for special [PATH=/opt/httpd/www.example.com/] sections in php.ini. All directives set in these sections will not be able to be overridden in user-defined ini-files or during runtime in the specified path.
  • Improved php.ini handling:
    • Added better error reporting for syntax errors in php.ini files
    • Allowed “ini-variables” to be used almost everywhere ini php.ini files
    • Allowed using alphanumeric/variable indexes in “array” ini options
    • Fixed get_cfg_var() to be able to return “array” ini options

And we can get some more information from the related php.ini addition:

1
2
3
4
5
6
7
8
9
10
11
+;;;;;;;;;;;;;;;;;;;;
+; php.ini Options  ;
+;;;;;;;;;;;;;;;;;;;;
+; Name for user-defined php.ini (.htaccess) files. Default is &qout;user.ini&qout;
+;user_ini.filename = &qout;user.ini&qout;
+
+; To disable this feature set this option to empty value
+;user_ini.filename =
+
+; TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes)
+;user_ini.cache_ttl = 300

OpenID support

In PHP 5.3 the openssl extension will provide high speed Diffie-Hellman support, which is important for OpenID. You can get more information from Dmitry Stogov’s proposal.

XSLT profiling

Christian Stocker mentioned in his blog that he added his XSLT profiling to the official PHP source.

getopt() on any platform

As from PHP 5.3 the getopt() function will be available even on Windows systems, and getopt() will support longopts on every system.

Error levels

E_STRICT will be splitted to E_STRICT and E_DEPRECATED. E_STRICT error will mean common bad practices and E_DEPRECATED will be triggered when you try to use such a language feature which is likely to go away from a later version. E_STRICT will be part of E_ALL.

Other improvements

  • Sqlite3 support via the ext/sqlite extension
  • array_replace[_recursive] functions
  • SPL improvements:

    • DirectoryIterator implements ArrayAccess
    • Implementing Spl(Array|Index|Member)Reference
    • Implement DualIterator
    • Implement RecursiveTreeIterator

17 Responses to “What is new in PHP 5.3 – part 4: __callStatic, OpenID support, user.ini, XSLT profiling and more”

  1. Emul said:

    i think you should sleep a bit sometimes :)
    Anyway, great articles. I cant wait for more.

  2. Tane Piper said:

    In this list, Improved ini handling and OpenID support seem the most interesting to me – hopefully with this inclusion we should see OpenID become more popular on the web.

  3. Adam said:

    I don’t mind the __callStatic naming, but I wish they’d stick to some standard with those. For instance, __call becomes ambiguous when you add _callStatic and so appending another word onto __call would be advisable in order to make clear what it does and doesn’t do.

  4. developercast.com » Gergely Hodicska’s Blog: What is new in PHP 5.3 - Part 4 said:

    [...] Hodicska has posted part four of his “what’s new in PHP 5.3″ series – a sort of “wrapup” for some [...]

  5. Schmalls said:

    I would really like to see nowdocs implemented in 5.3. It would definitely make a lot of code more readable instead of having to escape things or use concatenation in long strings.

  6. PHP 5.3 : le tour des nouveautés said:

    [...]  What is new in PHP 5.3 – part 4 (0 visite) [...]

  7. Pro::PHP Newscast (November 22, 2007) | PHP Podcasts said:

    [...] What’s coming in PHP 5.3 Listen [...]

  8. open source said:

    Looks fine :)

  9. Les said:

    I think the name convention of using __callStatic(); is just plain ugly, and those that be should have left it as it was, and let PHP it’s self determine if the call to the class method was static or dynamic.

    I can only pray that those that be don’t go ahead (as you suggest?), and make the changes to the other magic methods. In fact, can we have __callStatic(); removed (now)? ;)

  10. meeero said:

    are there any docs available for these ini-directives?

  11. János Pásztor said:

    What I cannot understand about PHP versions is, that most basic things are missing, yet they implement OpenID. It is to me as if the dev’s would implement any fancy feature which comes their way but pay little attention to the small details.

    Anyway, language elements are a welcome addition and I’m really happy about .htaccess FastCGI options. Sometimes, it’s a real pain in the neck to configure something without them.

  12. Rafael S. Souza said:

    I dont known if the problem is with my build version, but, $method parameter of __callStatic returns method name in lower case, its very wrong.

    It happened with function get_class in previous versions, later it was fixed. i hope it will be fixed.

  13. Piotr `Athlan` Pelczar /dev/blog » Blog Archive » Vframe 2.2 said:

    [...] w wersji 5.4 idzie w bardzo dobrym kierunku. Zapowiada się implementacja magicznej metody __callStatic() analogicznej do __call(). Problem będzie w instalacji najnowszej wersji na polskich serwerach. W [...]

  14. News d’été ! | Julien Breux said:

    [...] En attendant, une petite news: PHP5.3 intégrera la méthode magique __callstatic. [...]

  15. greencard said:

    it looks like a nice site, thanks..

  16. anup said:

    __construct()
    __destruct()
    __call()
    __callStatic()
    __get()
    __set()
    __isset()
    __unset()
    __sleep()
    __wakeup()
    __toString()
    __set_state()
    __clone()
    serialize()
    unserialize()

    can you give explanation of these magic method when the method is called and what is the use of every method? I am learning PHP.
    thank you

  17. PHP 5.3 Zone virtuaalserverites « ZONE.EE said:

    [...] dynamic static calls – Klassi meetodi dünaamiline väljakutsumine. Kui enne pidi dünaamiliseks väljakutsumiseks kasutama kohmakaid call_user_func/call_user_func_array funktsioone, siis alates 5.3-st piisab järgmisest: $cls = “Klass123″; $meth = “doSomething”; $result = $cls::$meth ($param1); [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>