DEVSENSE / Phalanger

PHP 5.4 compiler for .NET/Mono frameworks. Predecessor to the opensource PeachPie project (www.peachpie.io).
http://v4.php-compiler.net/
Apache License 2.0
381 stars 92 forks source link

Support for PHP 5.4 traits #42

Open endel opened 9 years ago

endel commented 9 years ago

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.

jakubmisek commented 9 years ago

Phalanger parses code containing traits use, but it does not support their compilation. The method or operation is not implemented.

endel commented 9 years ago

@jakubmisek Thank you for your quick response! I will try without compiling it.

Phalanger looks freaking great, what a hard work you did here!

jakubmisek commented 9 years ago

Thank you!

Anyway traits are not implemented yet. Phalanger compiles everything, so it can't run "without compiling it". :-)

endel commented 9 years ago

@jakubmisek got it!

Do you think it will be implemented later in Phalanger 4.x.x?

endel commented 9 years ago

@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.

jakubmisek commented 7 years ago

The feature will be implemented in https://github.com/peachpiecompiler/peachpie