Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Support for PHP 5.4 traits #42

Open
endel opened this issue Dec 14, 2014 · 6 comments
Open

Support for PHP 5.4 traits #42

endel opened this issue Dec 14, 2014 · 6 comments

Comments

@endel
Copy link
Contributor

endel commented Dec 14, 2014

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
Copy link
Member

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

@endel
Copy link
Contributor Author

endel commented Dec 14, 2014

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

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

@endel endel closed this as completed Dec 14, 2014
@jakubmisek
Copy link
Member

Thank you!

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

@endel
Copy link
Contributor Author

endel commented Dec 14, 2014

@jakubmisek got it!

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

@endel
Copy link
Contributor Author

endel commented Dec 30, 2014

@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
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants