peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.31k stars 202 forks source link

System.ArgumentNullException: Value cannot be null. (Parameter 'tinfo') #1022

Open vvtll opened 2 years ago

vvtll commented 2 years ago
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'tinfo')
   at Pchp.Core.Context.Create(RuntimeTypeHandle caller, PhpTypeInfo tinfo, PhpValue[] arguments)
   at <Root>.program_php.<Main>(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>) in /home/chenfa/proj/mytestall_dir/helloword/program.php:line 5
   at <Script>.Main(String[] args)

This is program.php code:

<?php

$testClass = '\\vvtll\\People';

$p = new $testClass();
$p->sing();

This is People.php code in vvtll namepace:

<?php
namespace vvtll;

class People
{
    public function __construct()
    {
        echo 'people class test';
    }
    public function sing()
    {
        echo 'hello world';
    }
}

my helloworld msbuildproj code:

<Project Sdk="Peachpie.NET.Sdk/1.0.0-dev">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <StartupObject>program.php</StartupObject>
    <Description>Simpliest PHP project for .NET Core, a console application.</Description>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**/*.php" />
  </ItemGroup>
    <PropertyGroup>
      <IlcOptimizationPreference>Speed</IlcOptimizationPreference>
      <IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
    </PropertyGroup>
    <ItemGroup>
      <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-alpha.1.21423.2" />
    </ItemGroup>

</Project>
jakubmisek commented 2 years ago

you're missing to include the file with People:

include 'People.php';

$testClass = '\\vvtll\\People';

$p = new $testClass();

Although; PeachPie should report a better error message.

Additionally, you can use composer.json with "autoload" so the include won't be necessary

vvtll commented 2 years ago

it is autoloaded by compose.json

vvtll commented 2 years ago

it can not work with the magic compiler "Microsoft.DotNet.ILCompiler"