XP8
thekid opened this issue ยท 6 comments
Scope of Change
This RFC defines what will be in XP8.
Rationale
Document features, changes and migration.
Functionality
XP8 will be the first framework release to be PHP7 only. For a feature overview of PHP7, see https://wiki.php.net/rfc#php_70
Return types
Return types will be adopted.
Scalar type hints
Scalar type hints will be added.
Anonymous class support
PHP7 supports a new class() { ... }
syntax - see https://wiki.php.net/rfc/anonymous_classes - which can replace our newinstance()
core functionality. Example:
$ git diff
diff --git a/.../StringOfTest.class.php b/.../StringOfTest.class.php
index c83da31..6424cc6 100644
--- a/src/test/php/net/xp_framework/unittest/core/StringOfTest.class.php
+++ b/src/test/php/net/xp_framework/unittest/core/StringOfTest.class.php
@@ -18,9 +18,9 @@ class StringOfTest extends \unittest\TestCase {
* @return lang.Object
*/
protected function testStringInstance() {
- return newinstance(Object::class, [], [
- 'toString' => function() { return 'TestString(6) { String }'; }
- ]);
+ return new class() extends Object {
+ public function toString() { return 'TestString(6) { String }'; }
+ };
}
Null-coalesce ??
Code will be rewritten where applicable, greatly improving readability:
diff --git a/src/main/php/util/Properties.class.php b/src/main/php/util/Properties.class.php
index 53746cb..a16a69f 100755
--- a/src/main/php/util/Properties.class.php
+++ b/src/main/php/util/Properties.class.php
@@ -284,10 +284,7 @@ class Properties extends \lang\Object implements PropertyAccess {
*/
public function readSection($name, $default= []) {
$this->_load();
- return isset($this->_data[$name])
- ? $this->_data[$name]
- : $default
- ;
+ return $this->_data[$name] ?? $default;
}
Comparison <=>
.
Code can be rewritten to use the "spaceship" operator.
Closure::call
Code in various places can benefit from https://wiki.php.net/rfc/closure_apply
Group use
Coding standards will be update to include https://wiki.php.net/rfc/group_use_declarations
Throwable
Places catching \Exception and \Throwable to ensure PHP 5 and PHP 7 compatibility can be rewritten to only catch the latter.
Context sensitive lexer
Methods can now use keywords - see https://wiki.php.net/rfc/context_sensitive_lexer. This can be used in the framework and libraries.
Unicode
Code can benefit from the added \u{xxxxx} Unicode Codepoint Escape Syntax.
Security considerations
n/a
Speed impact
Faster when replacing newinstance() with native anonymous class support
Dependencies
PHP 7.0
Related documents
We can use new class(...) extends self
inside enums if php/php-src#1779 is merged.
Example:
abstract class Operation extends \lang\Enum {
public static $plus, $minus, $times, $dividedBy;
static function __static() {
self::$plus= new class(0, 'plus') extends self() {
static function __static() { }
public function apply($a, $b) { return $a + $b; }
}
// ...
}
public abstract function apply($a, $b);
}
Rewrote code...
- ...to use anonymous classes.
- ...to use
??
- ...to use
<=>
- ...to use grouped use statements
- ...and replaced all \Exception (PHP5) handling with \Throwable (PHP 7)
Compact Apidoc Syntax variation
When using (primitive) parameter and return type hints, the apidoc tags feel unnecessary. For examle:
class T {
/**
* Creates a string representation
*
* @return string
*/
public function toString() {
return 'T';
}
}
RFC #284 already introduced compact apidoc syntax by only adding /** @return string */
as doc comment and omitting the description. This is superfluent in XP8, because the string type can be used as syntax. For XP8, I suggest we re-add the doc comment again, but let it contain the description. It does feel funny completely without!
class T {
/** Creates a string representation */
public function toString(): string { return 'T'; }
}
โ Added PHP 7.1 to Travis-CI in xp-framework/core@c3b78cd
Libraries to support XP8
xp-framework
- https://github.com/xp-framework/unittest/releases/tag/v7.1.0
- https://github.com/xp-framework/rest/releases/tag/v7.3.0
- https://github.com/xp-framework/scriptlet/releases/tag/v8.3.0
- https://github.com/xp-framework/logging/releases/tag/v7.1.0
- https://github.com/xp-framework/ldap/releases/tag/v7.4.0
- https://github.com/xp-framework/tokenize/releases/tag/v7.1.0
- https://github.com/xp-framework/rdbms/releases/tag/v9.0.0 (๐ major version!)
- https://github.com/xp-framework/http/releases/tag/v8.0.0 (๐ major version!)
- https://github.com/xp-framework/xml/releases/tag/v8.0.0 (๐ major version!)
- https://github.com/xp-framework/collections/releases/tag/v7.2.0
- https://github.com/xp-framework/math/releases/tag/v7.1.0
- https://github.com/xp-framework/io-collections/releases/tag/v7.1.0
- https://github.com/xp-framework/mail/releases/tag/v7.1.0
- https://github.com/xp-framework/networking/releases/tag/v8.0.0 (๐ major version!)
- https://github.com/xp-framework/ftp/releases/tag/v7.1.0
- https://github.com/xp-framework/zip/releases/tag/v7.1.0
- https://github.com/xp-framework/command/releases/tag/v7.2.0
- https://github.com/xp-framework/patterns/releases/tag/v7.1.0
- https://github.com/xp-framework/text-encode/releases/tag/v7.1.0
- https://github.com/xp-framework/csv/releases/tag/v7.1.0
- https://github.com/xp-framework/imaging/releases/tag/v7.1.0
xp-forge
- https://github.com/xp-forge/json/releases/tag/v2.2.0
- https://github.com/xp-forge/sequence/releases/tag/v6.1.0
- https://github.com/xp-forge/inject/releases/tag/v3.1.0
- https://github.com/xp-forge/parse/releases/tag/v1.1.0
- https://github.com/xp-forge/mirrors/releases/tag/v4.2.0
- https://github.com/xp-forge/partial/releases/tag/v2.1.0
- https://github.com/xp-forge/mustache/releases/tag/v4.0.0 (๐ major version!)
- https://github.com/xp-forge/handlebars/releases/tag/v3.0.0 (๐ major version!)
- https://github.com/xp-forge/markdown/releases/tag/v3.1.0
- https://github.com/xp-forge/keepass/releases/tag/v0.5.0
- https://github.com/xp-forge/nsca/releases/tag/v5.1.0
- https://github.com/xp-forge/yaml/releases/tag/v3.1.0
- https://github.com/xp-forge/stomp/releases/tag/v9.1.0
- https://github.com/xp-forge/pivot/releases/tag/v1.1.0
- https://github.com/xp-forge/geoip/releases/tag/v2.1.0
XP8 release
- XP8 has been released: https://github.com/xp-framework/core/releases/tag/v8.0.0
- XP7 now in seven branch, master at XP8