PHP5

PHP 5.3 and typesafe enumerations

at 2008-08-12 in PHP5 by friebe

Within RFC #0132, typesafe enumerations were added to the XP framework. Because PHP does not support them language-wise, we need a bit of workaround syntax to make them work.

With PHP 5.3 and its so-called "late static binding features", enum declarations can now be written much more compact for the simplest use-case. Example:

<?php 
class TransactionType extends Enum {
public
static $NOT_SUPPORTED, $REQUIRED, $SUPPORTS, $NEVER;
}
?>


(more)

PHP 5.3

at 2008-08-08 in PHP5 by friebe

I've started playing around with the first alpha release of PHP 5.3 (should be released around September or October this year), see also the PHP 5.3 alpha1 announcement from August 1st.

Some first observations:


(more)

RFC #0092: Switching from PHP4 to PHP5

at 2006-12-18 in PHP5 by kiesel

Tomorrow, RFC #0092 will be set to status implemented. With its implementation, the XP framework's newest version will work with PHP5 only.

If you are running XP and have an application that you don't want to change and just leave it as is - here's how to achieve that:


(more)

Running PHP4 and PHP5 at the same time

at 2006-12-10 in PHP5 by kiesel

RFC #0092 is about the strategy that the XP framework will follow when doing it's step to PHP5 - from the strategic point of view.

It's quite obvious that 3rd party applications cannot be run under a 5.xx version of XP from one day to the other (well, actually it could, but the problem here is that quite a number of applications exist and you cannot take care for them all at a single moment), so systems need to provide a backwards compatible way of doing this step.

What that means is: we need to be able to run PHP4 and PHP5 on the same host, as CLI and in a web environment.

The setup, this article is going to feature is having PHP4 as a Apache module and PHP5 as CGI.


(more)

Why we should migrate to PHP5

at 2005-02-06 in PHP5 by friebe

Migrating to PHP5 (plain, as released by the PHP team) is currently not possible:

  • Builtin classes like Exception and Iterator take names we've already used.
    So much for BC here. See also entry #16
  • The one-super-class-for-all rule of XP is broken as built-in Exception needs to be the base class of anything that can be throw()n
    I've discussed this earlier, in entry #11
  • Serialization is incompatible
    A class with private and protected members serialized in PHP5 will not be readable by PHP4's serialize(). That prevents us from being able to migrate parts of our web applications relying on a defined session format.

Of course, by using our patch, we can get around the first two of these issues (at least, at its current state). An addition to the patch could also fix up the third.

But let's also have a look at the other side, why it would make sense to upgrade:


(more)

The patch showcase: self

at 2005-01-09 in PHP5 by friebe

The keyword self can be used like $this for static classes - the problem with the current implementation is that it does not respect the "runtime class" (don't know how to describe this any better...). See also this discussion on the PHP developer's mailinglist.

As of today the patch fixes this. The following now works as one would intuitively expect:

<?php 
class A {
protected
static $instance = NULL;

public
static function getInstance() {
if
(!self::$instance) {
self::
$instance= new self();
}
return self::
$instance;
}
}

class B extends A { }

echo get_class
(B::getInstance());
?>

This outputs "B" - credits go to Alex:)



The patch: BC problem fixed

at 2005-01-09 in PHP5 by friebe

The commit message of the patch's revision 1.25 read:


- Implement instance creation expressions
- Disallow omitting brackets in class construction statements:
new Test; is now illegal

Reasoning behind this was that I couldn't figure out how to solve a shift/reduce conflict in the grammar - I finally had an idea on how to get around it yesterday and fixed it today. The patch is now BC-break free:)



JDK 1.5

at 2004-12-02 in PHP5Further reading by friebe

What do you like best about JDK 1.5? This is what I asked a colleague of mine at work today after she told me she was already using it. Well:

  • The enhanced for statement
  • Enums
  • Generics
If this sounds interesting to you, have a look at New Language Features for Ease of Development in the Java 2 Platform, Standard Edition 1.5: A Conversation with Joshua Bloch at java.sun.com.


(more)

The patch: PHP5 packages (a.k.a. "namespaces") - basics

at 2004-12-02 in PHP5 by friebe

When asked in a reader's poll in George Schlossnagle's blog what people thought PHP5 was missing, request #1 was namespaces (or packages), or short: A way to avoid name clashes between classes.

With SPL and the new dom extension, the number of builtin classes has risen enormously (4.3.8: 21, 5.0.0: 55, 5.1.0-dev: 63), with a lot of good names taken, Iterator, Exception, Reflection and Traversable, to name only the most eminent. Any person having a halfway decent object-oriented framework will maybe have used these names already, asking him- or herself: When will it stop? Which class name will pollute the global namespace (the only in current PHP5 releases) next? How many more classes will I have to rename (and introduce API breaks with it)?

This is exactly the case with the XP framework. As you know, we have had Exception and Iterator for a long long time. Both of these are defined as built-in classes as of the first release of PHP5.


(more)

The patch feature showcase: Operator overloading

at 2004-12-02 in PHP5 by friebe

"The patch" (still doesn't have a name yet) implements operator overloading in PHP5. Not all operators can be overloaded, however.


Operators           Overloadability
------------------- ----------------------------------------------------
++, --, !           These unary operators can be overloaded.
+, -, \*, /, %       These binary operators can be overloaded.
+=, -=, \*=, /=, %=  Assignment operators cannot be overloaded, but +=, 
                    for example, is evaluated using +, which can be 
                    overloaded.
== != < > <= >=     Comparison operators can be overloaded, but only
                    all of them at once, using the compare operator
                    (see below).


The key to operator overloading is the new keyword "operator". Apart from that, the syntax is equal to that of a normal method declaration:

Abbreviated example:

<?php 
class Integer {

public
static operator + (Integer $a, Integer $b) {
return
new Integer($a->value + $b->value);
}
}
?>


(more)

Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases