Can't access PHP builtins from inside subclass constructor
6 posts
• Page 1 of 1
Can't access PHP builtins from inside subclass constructor
I'm trying to run MediaWiki language conversions using Phalanger 3.0.0.3406, but I'm hitting an odd problem with accessing builtin PHP functions from certain places. Even though I've referenced PhpNetClassLibrary, this is the error: "Call to undefined function: 'array_merge'"
I've reduced the problem to a few lines of code across 2 files. The problem goes away when only one file is used. The problem also goes away if I remove the class inheritance.
Here's the first file (example.php):
Here's the second file (LanguageZh.php):
And here's how I tried to compile:
The main difference that I see in the compiled bytecode between the crashing-2-file-version of this example and the no-problem-1-file-version, is that LanguageZh turns into a CLR class in the 1-file-version, but in the 2-file-version, it only exists as an unevaluated string argument to DynamicCode.Eval. (I don't know if this is a significant difference or not.)
I've reduced the problem to a few lines of code across 2 files. The problem goes away when only one file is used. The problem also goes away if I remove the class inheritance.
Here's the first file (example.php):
- Code: Select all
<?php
class Language {
}
include "LanguageZh.php";
echo "Top level sleep...\n";
print_r(array_merge(array(1 => 2)));
echo "...done\n";
new LanguageZh();
?>
Here's the second file (LanguageZh.php):
- Code: Select all
<?php
class LanguageZh extends Language {
function __construct() {
echo "Constructor sleep...\n";
print_r(array_merge(array(1 => 2)));
echo "...done\n";
}
}
?>
And here's how I tried to compile:
- Code: Select all
phpc.exe /out:example /entrypoint:example.php example.php /r:PhpNetClassLibrary.dll
The main difference that I see in the compiled bytecode between the crashing-2-file-version of this example and the no-problem-1-file-version, is that LanguageZh turns into a CLR class in the 1-file-version, but in the 2-file-version, it only exists as an unevaluated string argument to DynamicCode.Eval. (I don't know if this is a significant difference or not.)
- dancecile
- Posts: 3
- Joined: September 6th, 2012, 7:52 pm
Re: Can't access PHP builtins from inside subclass construct
Hi,
I tried your test case, and everything works ok for me. I'm getting following output:
DynamicCode.Eval is feature, the code have to be compiled in runtime, because the base class of LanguageZh is not known in compile time (you would have to add 'include "example.php";' in LanguageZh.php to let compiler know, the base class is really that class Language you expect. (imagine you somewhere include LanguageZh.php without example.php ... with another class Language declared)
I tried your test case, and everything works ok for me. I'm getting following output:
- Code: Select all
Top level sleep...
Array
(
[0] => 2
)
...done
Constructor sleep...
Array
(
[0] => 2
)
...done
DynamicCode.Eval is feature, the code have to be compiled in runtime, because the base class of LanguageZh is not known in compile time (you would have to add 'include "example.php";' in LanguageZh.php to let compiler know, the base class is really that class Language you expect. (imagine you somewhere include LanguageZh.php without example.php ... with another class Language declared)
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Can't access PHP builtins from inside subclass construct
OK, that makes sense why DynamicCode.Eval would be used. And yup, the output you got is the correct output.
I'm not quite sure what to do next. I getting same error on both Windows 7 (.NET 4.5) and Ubuntu (Mono 2.10.8), so I don't think I've misconfigured my system. If it makes a difference, I didn't use the Phalanger installer, I'm just using the binaries in the same folder as my PHP files.
I've downloaded the latest Phalanger code from Github. I built phpc.exe, PhpNetClassLibrary.dll, and PhpNetCore.dll, and used them to compile my two files. Unfortunately, I'm still getting the same error. How can I get more info to debug deeper into this?
I'm not quite sure what to do next. I getting same error on both Windows 7 (.NET 4.5) and Ubuntu (Mono 2.10.8), so I don't think I've misconfigured my system. If it makes a difference, I didn't use the Phalanger installer, I'm just using the binaries in the same folder as my PHP files.
I've downloaded the latest Phalanger code from Github. I built phpc.exe, PhpNetClassLibrary.dll, and PhpNetCore.dll, and used them to compile my two files. Unfortunately, I'm still getting the same error. How can I get more info to debug deeper into this?
- dancecile
- Posts: 3
- Joined: September 6th, 2012, 7:52 pm
Re: Can't access PHP builtins from inside subclass construct
Ok, I can see it.
Since the code in DynamicCode.Eval is compiled in run time, you need to let Phalanger know what libraries you reference in run time too.
Following
Since the code in DynamicCode.Eval is compiled in run time, you need to let Phalanger know what libraries you reference in run time too.
Following
- Code: Select all
/r:PhpNetClassLibrary.dll
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Can't access PHP builtins from inside subclass construct
Perfect, thanks. That did the trick. My small example is fixed, and my full MediaWiki language conversion works fine too now.
For the record, here's the example.exe.config file that I used:
I can update that wiki page if you'd like. Is it okay if I reorganize it a bit to separate web and non-web applications?
For the record, here's the example.exe.config file that I used:
- Code: Select all
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="phpNet" type="PHP.Core.ConfigurationSectionHandler, PhpNetCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=0a8e8c4c76728c71" />
</configSections>
<phpNet>
<classLibrary>
<add assembly="PhpNetClassLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4af37afe3cde05fb" section="bcl" />
</classLibrary>
</phpNet>
</configuration>
I can update that wiki page if you'd like. Is it okay if I reorganize it a bit to separate web and non-web applications?
- dancecile
- Posts: 3
- Joined: September 6th, 2012, 7:52 pm
Re: Can't access PHP builtins from inside subclass construct
Great! Thanks for the config file, I'm sure other people will find it helpful.dancecile wrote:Perfect, thanks. That did the trick. My small example is fixed, and my full MediaWiki language conversion works fine too now.
Please, feel free to update any information you find useful. (I have to create you an account)dancecile wrote:I can update that wiki page if you'd like.
Actually they are the same, just web applications have config file normally, so this wouldn't happen. But it would probably prevent similar issues with Phalanger, so ok.dancecile wrote:Is it okay if I reorganize it a bit to separate web and non-web applications?
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 19 guests