Phalanger
Phalanger copied to clipboard
Support for PHP 5.4 traits
Does Phalanger already supports traits?
I'm trying to build this simple example from PHP documentation:
<?php
class Base {
public function sayHello() {
echo 'Hello ';
}
}
trait SayWorld {
public function sayHello() {
parent::sayHello();
echo 'World!';
}
}
class MyHelloWorld extends Base {
use SayWorld;
}
$o = new MyHelloWorld();
$o->sayHello();
Errors and stack trace using Visual Studio 2013 and Phalanger 4.0:
Error 1 The class 'SayWorld' has no parent c:\users\endel\documents\visual studio 2013\Projects\PhalangerTraits\PhalangerTraits\index.php 10 10 PhalangerTraits
Error 2 Internal error!
Please, report this bug via http://phalanger.codeplex.com/workitem/list/basic.
Additional information:
The method or operation is not implemented.
at PHP.Core.Compiler.AST.NodeCompilers.TraitsUseCompiler.Analyze(TraitsUse node, Analyzer analyzer)
at PHP.Core.Compiler.AST.NodeCompilers.TypeMemberDeclCompiler`1.PHP.Core.Compiler.AST.ITypeMemberDeclCompiler.Analyze(TypeMemberDecl node, Analyzer analyzer)
at PHP.Core.Compiler.AST.NodeCompilers.TypeDeclCompiler.Analyze(TypeDecl node, Analyzer analyzer)
at PHP.Core.Compiler.AST.NodeCompilers.StatementCompiler`1.PHP.Core.Compiler.AST.IStatementCompiler.Analyze(Statement node, Analyzer analyzer)
at PHP.Core.Compiler.AST.NodeCompilers.GlobalCodeCompiler.Analyze(GlobalCode ast, Analyzer analyzer)
at PHP.Core.Analyzer.Analyze(CompilationSourceUnit sourceUnit)
at PHP.Core.Reflection.ScriptCompilationUnit.AnalyzeRecursively(Analyzer analyzer)
at PHP.Core.Reflection.InclusionGraphBuilder.AnalyzeDfsTree(PhpSourceFile rootSourceFile)
at PHP.Core.Emit.ScriptAssemblyBuilder.CompileScripts(IEnumerable`1 sourceFiles, CompilationContext context)
at PHP.Core.Emit.ScriptAssemblyBuilder.Build(IEnumerable`1 sourceFiles, CompilationContext context)
at PHP.Core.ApplicationCompiler.Compile(ApplicationContext applicationContext, CompilerConfiguration config, ErrorSink errorSink, CompilationParameters ps)
-1 0 PhalangerTraits
Since the error tells about "PhalangerTraits", I suppose it is implemented somehow, correct? Am I missing something here?
Thank you.
Phalanger parses code containing traits use, but it does not support their compilation. The method or operation is not implemented.
@jakubmisek Thank you for your quick response! I will try without compiling it.
Phalanger looks freaking great, what a hard work you did here!
Thank you!
Anyway traits are not implemented yet. Phalanger compiles everything, so it can't run "without compiling it". :-)
@jakubmisek got it!
Do you think it will be implemented later in Phalanger 4.x.x?
@jakubmisek
I'm using this tool to convert PHP 5.4+ into PHP 5.3 standards, which covers downgrading PHP Traits https://github.com/endel/php-code-downgrade/
So if there are any plans in supporting this, it could hold on for a while.
The feature will be implemented in https://github.com/peachpiecompiler/peachpie