Phalanger cant find my php classes

对着背影说爱祢 提交于 2020-01-14 05:45:09

问题


After this question I found a good (up to date) example to follow here. I successfully got PHP.Core libraries working in VS but still having problems finding my php classes.

The tutorial is simple enough however

dynamic phpObj = globals.@class.PhpClass();

never finds my php class. I have tried with the example file default.php (classname: PhpClass) and with my own php classes which are similar but have a different name.

What am I missing here? I have tried the option

Project Properties>Package/Publish Web>Items to deploy>all files in project

but that didnt help. Currently I have my php classes just under the project as seen below

The error I get just says it cant find the class:

Using ILSpy here is the main snippet of code for CurrentContext

result = (((ScriptContext)CallContext.GetData("PhpNet:ScriptContext")) ?? ScriptContext.CreateDefaultScriptContext());

This is the line of code that is used to find the php classes (AFAIK).


回答1:


You have to include your php files into the PHP context first ... In Web App, to 'simulate' php lifecycle properly, do following:

using (var request_context = RequestContext.Initialize(ApplicationContext.Default, HttpContext.Current))
{
    var context = request_context.ScriptContext;
    context.Include("default.php", false);
// now the declarations declared by default.php are available in context.
// do anything with PHP objects here
}


来源:https://stackoverflow.com/questions/12901567/phalanger-cant-find-my-php-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!