Skip to content

Bump PHP requirement to PHP 5.3.0 minimum #265

@thekid

Description

@thekid

Scope of Change

The minimum PHP requirement for the XP Framework master branch will be bumped from 5.2.10 (5.2.0 unofficially also worked!) to 5.3.0.

Rationale

This will enable us to work with namespaces, get_called_class(), static, and remove various PHP 5.2.x workarounds.

Functionality

Namespace adoption

We can possibly go farther than just supporting optional namespaces as described in RFC #222.

Problem: Namespaces and extension methods

Prior to namespaces, all classes used inside a class needed to be "used" via the uses statement. This would trigger the __import($scope) initializer. Imaging an Example class and and ExampleExtensions class - the latter providing an isEmpty() method.

uses('com.example.Example', 'vendor.ExampleExtensions', 'unittest.TestCase');

class ExampleUsageTest extends TestCase {
  #[@test]
  public function is_empty() {
    $this->assertTrue(create(new Example())->isEmpty());
  }
}

Now if we rewrite this to namespaces, the ExampleExtensions class' import initializer wouldn't necessarily be called any more, even if it existed inside a use statement, since that only triggers the autoloading mechanism if the class isn't defined! To work around this, we can re-add the uses() call, making things look funny because we now have mixed use and uses() statements.

A possible solution could be to add a thin wrapper to uses called import, resulting in the following picture:

use \com\example\Example;
use \unittest\TestCase;
import('vendor.ExampleExtensions');

class ExampleUsageTest extends TestCase {
  #[@test]
  public function is_empty() {
    $this->assertTrue(create(new Example())->isEmpty());
  }
}

Enum simplification

Enums can be declared with much less code - see xp-framework/xp-framework#229.

Named pipes

This could be removed:

core/src/main/php/rdbms/mysqlx/NamedPipe.class.php

  // Workaround for PHP bug #29005: "fopen() can't open NT named pipes on local
  // computer".
  if (0 === strncmp('\\\\.', $socket, 3)) {
    $socket= '\\\\127.0.0.1'.substr($socket, 3);
  }

Ternary shortcut

We could start using the ternary shortcut ?:.

Anonymous functions

We could (and should) investigate places where anonymous functions make sense in the XP Framework. An example of this would be in a REST client implementation:

  $request= create(new RestRequest('/resource/{id}'))->withSegment('id', $id);
  $response= $this->send($request, array(
    200 => function($result) { return $result->data('type.of.Resource'); }
    404 => function($result) { return NULL; }
  ));

Static "no such method" handler

Inside our root objects Object and Throwable, we have a __callStatic() implementation, which could be simplified as follows:

- $t= debug_backtrace();
- throw new Error('Call to undefined method '.$t[1]['class'].'::'.$name);
+ throw new Error('Call to undefined method '.get_called_class().'::'.$name);

Directory of current file

We can remove occurrences of dirname(__FILE__) and replace them with __DIR__.

System

We can change the lang.System class to use gethostname() inside System::getProperty('host.name') instead of having to rely on either the posix extension or environment variables.

Security considerations

None.

Speed impact

Better. 🐝

Dependencies

PHP 5.3.0

Related documents

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions