C# attributes in PHP

Discussion about the open-source Phalanger [?] project.

C# attributes in PHP

Postby analytik » September 19th, 2012, 2:04 pm

Hi,

I know nothing about C#, so sorry if this is a silly question.

I'm trying to port some code into PHP, as I want to develop in PHP to get a .NET dll. (The target should Player.IO's multiplayer server service.) The original C# code has

Code: Select all
using PlayerIO.GameLibrary;
...
namespace FridgeMagnets {
   [RoomType("FridgeMagnets")]
   public class GameCode : Game<Player> { ... }


[del]Is there any way to do this in Phalanger? Thanks.[/del]

EDIT: found the wiki page, sorry.

However, I'm still getting an error, when I tried to namespace the attribute with
[\PlayerIO\GameLibrary\RoomType("FridgeMagnets")]
I get error
Code: Select all
c:\...\FridgeMagnets.php(38,2): error PHP1120: Unknown custom attribute; neither of types 'PlayerIO\GameLibrary\RoomType' and 'PlayerIO\GameLibrary\RoomTypeAttribute' exists


The same thing happened when I didn't use namespace, it just complained about GameNamespace\RoomTypeAttribute doesn't exist. And I've added
Code: Select all
use PlayerIO\GameLibrary;
use PlayerIO\GameLibrary\RoomTypeAttribute;

to the beginning of the file, as well as
Code: Select all
<add url="Player.IO GameLibrary.dll" />

into project.phpproj
analytik
 
Posts: 3
Joined: September 19th, 2012, 11:27 am

Re: C# attributes in PHP

Postby Jakub Misek » September 19th, 2012, 5:14 pm

Hi,

your attribute syntax is ok.

Just
Code: Select all
<add url="Player.IO GameLibrary.dll" />
should not be placed in .phpproj file.

You have to paste it into a .config file (app.config), into <phpNet><classLibrary>,

or using Visual Studio, into project References (right click on project name, Add Reference -> select your DLL)
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: C# attributes in PHP

Postby analytik » September 19th, 2012, 6:45 pm

Perfect, thanks! That helped.

However, even when it stopped throwing errors, it probably wasn't all I needed to do to make the DLL work. So I tried pure mode, and after adding a few more use statements to my code, I got

Code: Select all
error PHP2007: Internal error!
Please, report this bug via http://www.codeplex.com/WorkItemList.aspx?ProjectName=Phalanger.
Additional information:
Object reference not set to an instance of an object.
   at PHP.Core.Reflection.GenericParameterDesc.Reflect()
   at PHP.Core.Reflection.DTypeDesc.get_Type()
   at PHP.Core.Reflection.ClrType.<>c__DisplayClass1.<MakeConstructedType>b__0(MakeGenericArgumentsResult error, DTypeDesc genericType, DTypeDesc argument, GenericParameterDesc parameter)
   at PHP.Core.Reflection.DTypeDesc.MakeGenericArguments(DTypeDesc[]& arguments, Int32& argCount, Action`4 onError)
   at PHP.Core.Reflection.ClrType.MakeConstructedType(Analyzer analyzer, DTypeDesc[] arguments, Position position)
   at PHP.Core.Analyzer.ResolveTypeName(GenericQualifiedName genericName, PhpType referringType, PhpRoutine referringRoutine, Position position, Boolean mustResolve)
   at PHP.Core.AST.TypeDecl.ResolveBaseType(Analyzer analyzer)
   at PHP.Core.AST.TypeDecl.PHP.Core.Reflection.IDeclarationNode.PreAnalyze(Analyzer analyzer)
   at PHP.Core.Analyzer.PreAnalyze(IEnumerable`1 declarations)
   at PHP.Core.Reflection.PureCompilationUnit.Compile(IEnumerable`1 sourceFiles, PureAssemblyBuilder assemblyBuilder, CompilationContext context, Encoding encoding)
   at PHP.Core.Emit.PureAssemblyBuilder.Build(IEnumerable`1 sourceFiles, CompilationContext context)
   at PHP.Core.ApplicationCompiler.Compile(ApplicationContext applicationContext, CompilerConfiguration config, ErrorSink errorSink, CompilationParameters ps)


Should I report it to CodePlex, or is it my fault?

The line of code that causes this is
Code: Select all
use PlayerIO\GameLibrary\Game;

(later in code used as class GameCode extends Game<:Player:> { ... })

so I assume the problem is because the Game class is defined in the external DLL as
Code: Select all
public abstract class Game<P> : PlayerIO.GameLibrary.Interfaces.BaseGame
   where P : new(), PlayerIO.GameLibrary.BasePlayer
    Member of PlayerIO.GameLibrary
analytik
 
Posts: 3
Joined: September 19th, 2012, 11:27 am

Re: C# attributes in PHP

Postby Jakub Misek » September 19th, 2012, 7:03 pm

Try to type "Player" as fully qualified name (including namespaces). There are some features missing in generics I guess.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: C# attributes in PHP

Postby analytik » September 19th, 2012, 8:10 pm

Jakub Misek wrote:Try to type "Player" as fully qualified name (including namespaces). There are some features missing in generics I guess.


Player was a locally defined class (in the same file), I got the error both when I tried FQCN, as well as just with Player. However, when I changed it to BasePlayer (the class from external DLL), it compiled successfully!

It still doesn't do what I wanted it to, but I've been warned that Player.IO's sandbox could be a trouble. Still, thanks for your help!
analytik
 
Posts: 3
Joined: September 19th, 2012, 11:27 am


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 35 guests

cron

User Control Panel

Login

Who is online

In total there are 35 users online :: 0 registered, 0 hidden and 35 guests (based on users active over the past 5 minutes)
Most users ever online was 330 on April 19th, 2024, 1:35 am

Users browsing this forum: No registered users and 35 guests