DEVSENSE / Phalanger

PHP 5.4 compiler for .NET/Mono frameworks. Predecessor to the opensource PeachPie project (www.peachpie.io).

Home Page:http://v4.php-compiler.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help, Custom entity class, can not convert type to [PHP.Core.IPhpVariable]

taotao2014 opened this issue · comments

=====c# code:======

static void Main(string[] args)
{
ScriptContext context = ScriptContext.CurrentContext;
context.Output = Console.Out;
context.Include(@"C:\script.php", true);
PhpReference r = context.Call("myTest", new WebClient(), new Student() { Age = 20, UserName = "David" });
Console.WriteLine(r.Value);
Console.ReadLine();

}

 public class Student
    {
        public string UserName { get; set; }
        public int Age { get; set; }
    }

=====script file:=====

Age=1000; echo $student->Age; //error,why?? //echo $student->UserName; //$page = $webClient->DownloadString('http://www.google.com'); //echo $page; return $student; } ``` ?>

hi,

There are few limitations when using this old API (context.Call). You have to 'wrap' Student into ClrObject first, so phalanger will be able to use it properly.

Use following call instead, so all this stuff is performed automatically

dynamic php = context.Globals; // dynamic context used to call functions, instantiate classes etc..
Student student = php.myTest(new WebClient(), new Student() { Age = 20, UserName = "David" });

for more info about dynamic context see Globals at http://www.php-compiler.net/blog/2012/net-interoperability-overview-of-phalanger-3-0

New, old model, have been resolved, thank you very much.