calling .net constructor from inheriting php class
Posted: January 3rd, 2016, 8:32 pm
I can't find a way to call .net constructor from inheriting php class:
Things I tried:
So how does one call the constructor?
- Code: Select all
❯ cat ../e.php
<?php
use System\Uri;
class ConstructorTest
{
public static function main()
{
}
}
class CustomUri extends Uri
{
public function __construct($uriString)
{
parent::__construct($uriString);
}
}
❯ Deployment/Debug/phpc.exe ../e.php /lang:CLR /r:/usr/lib/mono/4.5/mscorlib.dll /r:/usr/lib/mono/phalanger/PhpNetClassLibrary.dll /r:/usr/lib/mono/4.5/System.dll /out:e.exe /target:exe /encoding:UTF-8 /pure+ /entrypoint:../e.php /debug+
Phalanger - the PHP Language Compiler - version 4.0
for Microsoft (R) .NET Framework version 4.0
Arguments:
../e.php
/lang:CLR
/r:/usr/lib/mono/4.5/mscorlib.dll
/r:/usr/lib/mono/phalanger/PhpNetClassLibrary.dll
/r:/usr/lib/mono/4.5/System.dll
/out:e.exe
/target:exe
/encoding:UTF-8
/pure+
/entrypoint:../e.php
/debug+
Encoding cannot be loaded.
fileEncoding=""
Loaded libraries:
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Base Library (PhpNetClassLibrary)
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Performing compilation ...
/home/weirdan/src/e.php(13,21): error PHP1240: Expecting parent constructor call
/home/weirdan/src/e.php(15,9): error PHP1066: Class 'System\Uri' does not contain definition of method '__construct'
Statistics:
Compiled in 0:00.235.
AST: LibraryFunctionCalls = 0, UnknownFunctionCalls = 0
Build complete -- 2 errors, 0 warnings.
Things I tried:
- parent::__construct($string); // errors shown above
- $this->Uri($string); // error PHP1240: Expecting parent constructor call
- parent::Uri($string); // error PHP1240: Expecting parent constructor call
- $this->{".ctor"}($string); // error PHP1240: Expecting parent constructor call
- parent::{".ctor"}($string); // error PHP2014: Syntax error: unexpected token '{'
- call_user_func([$this, ".ctor"], $string); // error PHP1240: Expecting parent constructor call
- call_user_func(["Uri", ".ctor"], $string); // error PHP1240: Expecting parent constructor call
- call_user_func(["Uri", "Uri"], $string); // error PHP1240: Expecting parent constructor call
- call_user_func(["Uri", "__construct"], $string); // error PHP1240: Expecting parent constructor call
- Uri::Uri($string); // error PHP1240: Expecting parent constructor call
So how does one call the constructor?