peachpie icon indicating copy to clipboard operation
peachpie copied to clipboard

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

Open vvtll opened this issue 3 years ago • 3 comments

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>

vvtll avatar Jan 16 '22 16:01 vvtll

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

jakubmisek avatar Jan 16 '22 20:01 jakubmisek

it is autoloaded by compose.json

vvtll avatar Jan 16 '22 21:01 vvtll

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

vvtll avatar Jan 16 '22 21:01 vvtll