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
Scope of Change
The minimum PHP requirement for the XP Framework
masterbranch will be bumped from5.2.10(5.2.0 unofficially also worked!) to5.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
usesstatement. This would trigger the__import($scope)initializer. Imaging anExampleclass and andExampleExtensionsclass - the latter providing anisEmpty()method.Now if we rewrite this to namespaces, the
ExampleExtensionsclass' import initializer wouldn't necessarily be called any more, even if it existed inside ausestatement, since that only triggers the autoloading mechanism if the class isn't defined! To work around this, we can re-add theuses()call, making things look funny because we now have mixeduseanduses()statements.A possible solution could be to add a thin wrapper to
usescalledimport, resulting in the following picture: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
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:
Static "no such method" handler
Inside our root objects Object and Throwable, we have a
__callStatic()implementation, which could be simplified as follows:Directory of current file
We can remove occurrences of
dirname(__FILE__)and replace them with__DIR__.System
We can change the
lang.Systemclass to usegethostname()insideSystem::getProperty('host.name')instead of having to rely on either theposixextension or environment variables.Security considerations
None.
Speed impact
Better. 🐝
Dependencies
PHP 5.3.0
Related documents