GithubHelp home page GithubHelp logo

peachpiecompiler / peachpie Goto Github PK

View Code? Open in Web Editor NEW
2.3K 2.3K 198.0 67.87 MB

PeachPie - the PHP compiler and runtime for .NET and .NET Core

Home Page: https://www.peachpie.io

License: Apache License 2.0

C# 96.42% Batchfile 0.01% PowerShell 0.03% PHP 3.32% Shell 0.03% Lex 0.16% XSLT 0.03%
aspnet-core coreclr dotnet dotnetcore microsoft netstandard opensource pchpcompiler peachpie php php-compiler roslyn

peachpie's People

Contributors

aaurizon avatar andrew-demb avatar avriltank avatar bfistein avatar bgrainger avatar calvinbaart avatar crbrz avatar dlob avatar dpen2000 avatar drsdavidsoft avatar gitter-badger avatar gordon-matt avatar iamcarbon avatar indigo744 avatar jakubmisek avatar jan-pavlovsky avatar jdluzen avatar jimbobsquarepants avatar jondmcelroy avatar kendallb avatar kripper avatar liesauer avatar mahmoodvcs avatar matbech avatar petrroll avatar petrsvihlik avatar roberthusak avatar tobihille avatar tomatorcz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

peachpie's Issues

trait support

Implement support for using traits.
See http://php.net/manual/en/language.oop5.traits.php for specs.

Used trait should be instantiated inside the class as a private "compiler-generated" object. Its members exposed by the class as generated methods that will call members on the trait instance.

trait class

trait T {
  function t_foo() {}
}

... compiles into IL equivalent to following:

[PhpTrait] public sealed class T<TSelf> { // TSelf is type of the trait owner, resolves `self`, static fields and optimizes callsites
  readonly TSelf <this>; // actual instance of class that uses the trait

  public PhpValue t_foo() { return PhpValue.Null; }
}

using the trait

class X {
  use T;
}

... compiles into IL equivalent to following:

public class X {
  private readonly T <>_t; // trait instance

  X(Context <ctx>) { this.<>_t = new T<X>(<ctx>, this); }
  public virtual PhpValue t_foo() { return this.<>_t.t_foo(); } // forwarding call to the trait instance
}

Nested alias created when updating reference to array item from function

Consider the following test case:

<?php
function set(&$alias, $value) {
  $alias = $value;
}
function test() {
  $arr = ['foo' => null];
  set($arr['foo'], ['bar']);
  
  print_r(str_replace('a', 'o', $arr['foo']));
}
test();

Expected result:

Array
(
    [0] => bor
)

Actual result:

Arroy

The compiled function set is equal to this:

public static void set(Context <ctx>, PhpAlias alias, PhpValue value)
{
	PhpValue val = value.GetValue();
	value = val.DeepCopy();
	val = value.DeepCopy();
	alias.Value = PhpValue.Create(val.EnsureAlias());
}

The last line causes an alias to an alias to be stored in $arr['foo']. As a result, PhpValue.AsArray() called on $arr['foo'] in str_replace retrieves null, which causes that it is converted to a string.

Is Server project behave properly?

Hello peachpie team,

I am very happy that peachpie develops so well and you made a great job.
I just would like to ask if the asp.net core server behave properly. I know there is the php project which compiles it php data to CIL and there is the ASP.NET Core.
I was playing little bit and detected that (in my opinion) the asp.net core does not behave like static webserver should do (maybe I did some wrong configurations).

I was expecting the following : there should be a rootfolder in "/projectname/Server" and if i put a static file like "hello.txt" and I hit the URL "localhost:5004/hello.txt" the server should anwser. But I just got a white page.

First I was thinking "ok - they forgot app.UseStaticFiles();" but nope - its inside. ok - there is no rootfolder? added - no change. "have to add the rootfolder to csproj? nope the other templates like razor or MVC do not do too". -.- So .... "ok the most easy stuff was tried xD"

It is not an too important issue - but I am curious what could be the problem. ;)
I will also look little bit around - it must be a trivial stuff.

Soo :D thanks for your time and wish you all a great christmas time!
Merry christmas
dotChris90 / Christian

Errors when using $this in trait

Test case:

<?php
trait T {
  public function bar() {
    return $this instanceof C;
  }
}
class C {
  use T;
}
echo (new C)->bar();

Expected result: 1
Actual result: NotImplementedException thrown from CodeGenerator.EmitAsObject(TypeSymbol, bool) during compilation.

The same happens in the case of CodeGenerator.EmitConvertToPhpValue.

wordpress plugin compile error

Hi,

I succeed run the peachpie wordpress project.
But, when I copy all of my php site wp plugin (69 plugins) into peachpie wordpress, and dotnet run.
Get some xxx could not be resolved errors:

such as 'SimpleXMLIterator' could not be resolved.
and I have searched for SimpleXMLIterator, it's php-xml, php-simplexml lib.

All the error are the same, you can search this page for 'could not be resolved' to highlight it.

/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/w3-total-cache/lib/SNS/utilities/simplexml.class.php(31,27): error PHP2044: Type name 'SimpleXMLIterator' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordfence/vendor/wordfence/wf-waf/src/lib/json.php(918,38): error PHP2044: Type name 'PEAR_Error' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordpress-seo/vendor/xrstf/composer-php52/lib/xrstf/Composer52/AutoloadGenerator.php(30,33): error PHP2044: Type name 'Composer\Autoload\AutoloadGenerator' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordpress-seo/vendor/yoast/whip/tests/ConfigurationTest.php(3,33): error PHP2044: Type name 'PHPUnit_Framework_TestCase' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordpress-seo/vendor/yoast/whip/tests/MessageDismisserTest.php(36,36): error PHP2044: Type name 'PHPUnit_Framework_TestCase' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordpress-seo/vendor/yoast/whip/tests/MessagesManagerTest.php(3,35): error PHP2044: Type name 'PHPUnit_Framework_TestCase' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordpress-seo/vendor/yoast/whip/tests/MessageTest.php(3,27): error PHP2044: Type name 'PHPUnit_Framework_TestCase' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordpress-seo/vendor/yoast/whip/tests/RequirementsCheckerTest.php(11,39): error PHP2044: Type name 'PHPUnit_Framework_TestCase' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wordpress-seo/vendor/yoast/whip/tests/VersionRequirementTest.php(3,38): error PHP2044: Type name 'PHPUnit_Framework_TestCase' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]
/Users/xxx/git/peachpie-wordpress/website/wp-content/plugins/wp-media-category-management/include/class.dmppanels.php(3,39): error PHP2044: Type name 'DebugMyPluginPanel' could not be resolved. [/Users/xxx/git/peachpie-wordpress/website/website.msbuildproj]

Stack Overflow in SemanticsBinder.cs starting in BindExpression method.

When the expr parameter is type Devsense.PHP.Syntax.Ast.DirectFcnCall, an infinite loop occurs. It goes from:

var bound = BindExpressionCore(expr, access); // (Line 298)

if (expr is AST.VarLikeConstructUse varLikeConstructUse) return BindVarLikeConstructUse(varLikeConstructUse, access); // (Line 310)

if (expr is AST.FunctionCall funcCall) return BindFunctionCall(funcCall, access); // (Line 541)     

var boundinstance = (x.IsMemberOf != null) ? BindExpression(x.IsMemberOf, BoundAccess.Read/*Object?*/) : null; // (Line 450) 

var bound = BindExpressionCore(expr, access); // (Line 298)

Dotnet templates do not work.

I am following along with your website. I ran the following commands.

$ dotnet --version
$ 2.1.2
$ dotnet new -i Peachpie.Templates::*
$ Templates                                         Short Name                 Language          Tags
------------------------------------------------------------------------------------------------------------------
Console Application                               console                    [C#], F#, VB      Common/Console
Class library                                     classlib                   [C#], F#, VB      Common/Library
Peachpie console application                      peachpie-console           PHP               Console
Peachpie Class library                            peachpie-classlibrary      PHP               Library
Examples:
    dotnet new mvc --auth Individual
    dotnet new mstest
    dotnet new --help

Then when I run:

$ dotnet new peachpie-console

I get:

Usage: new [options]

Options:
  -h, --help          Displays help for this command.
  -l, --list          Lists templates containing the specified name. If no name is specified, lists all templates.
  -n, --name          The name for the output being created. If no name is specified, the name of the current directory
is used.
  -o, --output        Location to place the generated output.
  -i, --install       Installs a source or a template pack.
  -u, --uninstall     Uninstalls a source or a template pack.
  --type              Filters templates based on available types. Predefined values are "project", "item" or "other".
  --force             Forces content to be generated even if it would change existing files.
  -lang, --language   Specifies the language of the template to create.


Peachpie console application (PHP)
Author: Peachpie
    (No Parameters)

Calling non-public method from anonymous function inside class causes MethodAccessException

Test case:

<?php
class C {
    private function foo() { echo "foo"; }
    private static function bar() { echo "bar"; }

    public static function getFn() {
        return function () {
            (new C)->foo();
            C::bar();
        };
    }
}
C::getFn()();

Expected result: foobar
Actual result:

Unhandled Exception: System.MethodAccessException: Attempt by method '<Root>.main_php.anonymous@function(Closure)' to access method 'C.foo()' failed.
   at <Root>.main_php.anonymous@function(Closure <closure>) in C:\iolevel\peachpie-samples\console-application\main.php:line 153
   at anonymous@function#1(Closure , Context , PhpValue[] )
   at Pchp.Core.Reflection.RoutineInfo.Invoke(Context ctx, Object target, PhpValue[] arguments)
   ...

The anonymous function is compiled as a method of the script class (main_php). Therefore, it cannot access the private methods of C.

Closures inside classes cannot acces their private methods dynamically

The reason for this is the missing type context of such call site (related to #96). See the following test case:

<?php
class A {
  private function foo() {
    echo "foo";
  }

  public function bar($method) {
    $fn = function() use ($method) {
      $this->$method();
    };
    $fn();
  }
}

(new A)->bar('foo');

Expected result: foo
Actual result: 'foo' not found

Helping in currently-not-implemented libraries

Hi,
I want to help you in development, I saw your roadmap and saw that there are some libraries that haven't been implemented yet and decided to work on those.

May I use P/Invoke in implementation?
May I use external libraries in implementing these?
Or they must be pure C# and implemented totally by myself?

Support accessing static trait members and methods from outside

Test case:

<?php
trait T {
  public static function foo() {
    echo "foo";
  }
  public static $bar = "bar";
}
T::foo();
echo T::$bar;

Expected result: foobar

Actual result: Unhandled Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) - this is probably caused by the unfilled type parameter T0, because T::foo() is compiled as T<T0>.foo(ctx)

how to run the php framework ,like CI,Laravel?

I try run CI by peachpic . Its not work. visit http://localhost:5004/ output source of 'core/CodeIgniter.php';
like this:

`<?php
/**

  • CodeIgniter
  • An open source application development framework for PHP
  • This content is released under the MIT License (MIT)
  • Copyright (c) 2014 - 2017, British Columbia Institute of Technology
  • Permission is hereby granted, free of charge, to any person obtaining a copy
  • of this software and associated documentation files (the "Software"), to deal
  • in the Software without restriction, including without limitation the rights
  • to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  • copies of the Software, and to permit persons to whom the Software is
  • furnished to do so, subject to the following conditions:
  • The above copyright notice and this permission notice shall be included in
  • all copies or substantial portions of the Software.
  • THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  • IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  • FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  • AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  • LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  • OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  • THE SOFTWARE.
  • @Package CodeIgniter
  • @author EllisLab Dev Team
  • @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
  • @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
  • @license http://opensource.org/licenses/MIT MIT License
  • @link https://codeigniter.com
  • @SInCE Version 1.0.0
  • @filesource
    */
    echo 1;
    defined('BASEPATH') OR exit('No direct script access allowed');
    `

Compiler generated arguments ignored when calling on interface

Test case:

interface IA {
  public function foo();
}

class A implements IA
{
  public function foo() {
    print_r( func_get_args() );
  }
}

function test(IA $ia) {
  $ia->foo("lorem", "ipsum");
}

test(new A);

Expected:

Array
(
    [0] => lorem
    [1] => ipsum
)

Actual:

Array
(
)

Type resolving doesn't take current namespace into account

Consider the following sample:

<?php
namespace NS {
  class A {
    public function __construct() { echo "right"; }
  }

  function test() {
    new A();
  }
}

namespace {
  class A {
    public function __construct() { echo "wrong"; }
  }

  NS\test();
}

Expected result: right
Actual result: wrong

.NET core 2.0 and .NET Standard 2.0 support

Hello,
this is a great initiative, bringing PHP and dotnet communities together! keep up the good work!
is there any plan to bring support for .net standard and dotnet core version 2.0 ?

Problem with aliases stored in array indexed by variable

See the following test case:

<?php
function test() {
  $arr = [ 1 ];
  $i = 0;

  $first_ref =& $arr[$i];
  $first = $arr[$i];
  $arr[$i] = 0;
  
  echo $first_ref, " ", $first, "\n";
  print_r($arr);
}
test();

The output of PHP starts with 0 1 whereas Peachpie produces 0 0. The problem is that the alias is not dereferenced (PhpValue.GetValue()) during $first = $arr[$i]. If we replace all the usages of $i by 0, the dereferencing is added, though and the program correctly outputs 0 1.

Non-matching signature of extended interface method causes TypeLoadException

The interface IB produced from this code fails to load:

<?php
interface IB extends Iterator {
  public function next();
}

Result: System.TypeLoadException: Non-abstract, non-.cctor method in an interface.

The same happens if we replace Iterator with IA defined as:

interface IA {
  public function next($arg);
}

Is peachpie-web ready for netcore 2.0?

Hello Peachpie team,

first of all want to thank you that you bring PHP to the .NET World. You did great work. I was very happy to read your blog https://www.peachpie.io/2017/11/php-netstandard-2-0.html and so I took my Fedora netbook and though "try it out.". I took one of my older peachpie project solution (bases on the 0.7 templates / which i tried under windows 10), bring it to my Fedora and changed the versions from ASP.NET Core 1.1.0 to 2.0 and the peachpie packages from 0.7.0 to 0.8.0. The build worked fine but there was a runtime error when starting the ASP.NET Core server. Usual I use dotnet run -p ./XYZ.server/XYZ.server.csproj to start the peachpie app and before it always worked.

  • Error
    Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingMethodException: Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
    thrown at Pchp.Core.Context.get_GlobalServices() at peachpie.Library.PDO.PDODriver.RegisterAllDrivers()

  • Guess
    Maybe I did some mistakes in project file. It seems I selected a wrong Version of package or bad combination.

  • question
    Is my guess correct theoretically and is peachpie-web ready for .NET Core 2.0? :) just curious because console application and lib seems to work fine with .NET Core 2.0 on Fedora. So it must be the C# Server.

  • desired Christmas gift / wish for future ;)
    peachpie Web example could be modified for net core 2.0 so we peachpie fans can enjoy ASP.NET Core 2.0 based webservers. ;)

This issue is just a question and wish - no bug detection. By the way : great work with wordpress on .NET. impressive. ๐Ÿ‘

Restoring dependecies from VS Code yields an error

I start up VS Code like:

code .\web-application.sln

I am prompted to restore the dependencies.

I am met with the following error output in the terminal:

Restoring packages for c:\Projects\PeachPie\Samples\web-application\website\website.msbuildproj...
 Restoring packages for c:\Projects\PeachPie\Samples\web-application\app\app.csproj...
 Restoring packages for c:\Projects\PeachPie\Samples\web-application\website\website.msbuildproj...
C:\Program Files\dotnet\sdk\2.0.3\NuGet.targets(102,5): error : The local source 'c:\Projects\PeachPie\peachpie\.nugs' doesn't exist.
[c:\Projects\PeachPie\Samples\web-application\app\app.csproj]
Done: 1.

Support self:: in static trait methods accessed from outside

This issue is related to #135, aimed at the usage of self:: in such situations. Test case:

<?php
trait T {
  private static $bar = "right";
  public static function bar() {
    return self::$bar;
  }
}
class C {
  public static $bar = "wrong";
  public static function foo() {
    return T::bar();
  }
}
echo C::foo();
echo "\n";
echo T::bar();

Expected result:

right
right

Actual result:

wrong

Unhandled Exception: System.NotImplementedException: The method or operation is not implemented.
   at Pchp.Core.Dynamic.GetFieldBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)
   at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
   ...

Also, Debug.Assert(ReferenceEquals(newOwner.OriginalDefinition, this.ContainingSymbol.OriginalDefinition)) in FieldSymbol.AsMember fails during the compilation.

PHAR support

Compilation directly from PHAR, inclusion of files in PHAR, including PHAR stub.

The goal of this issue is to be able to compile phpunit from phar.

Classes

Runtime

  • include of a phar://
  • phar:// stream wrapper
  • phar:// alias (mapPhar)

Compiler

  • PHAR file parser
  • compilation of .phar file
  • skip first line of phar stub (#!/usr/bin)
  • magic constants inside PHAR entries (__FILE__ etc)
  • StartupObject to be .phar file
  • PHAR content files into resources

Redefinitions of method with default arguments can cause TypeLoadException

Consider the following code:

<?php
class A {
  function foo($a, $b = "") {}
}
class B extends A {
  function foo($a) {}
}
class C extends B {
  function foo($a) {}
}
class D extends C {
  function foo($a, $b) {}
}

When launched, it throws the following exception:

Unhandled Exception: System.TypeLoadException: Declaration referenced in a method implementation cannot be a final method. Type: 'D'.

It seems that D.foo(PhpValue, PhpValue) attempts to override the sealed method B.foo(PhpValue, PhpValue). Removing C from the inheritance chain prevents this error from appearing, because new virtual instead of override is then used.

Integrating Wordpress with ASP.NET MVC

With the Peachpie compiler I can see how I can get an existing Wordpress site up an running in a .NET environment. My question is, how can a Wordpress site be integrated with an MVC application? I realize that this is probably aWordpress and/or an ASP.NET question but most of the solutions that I have see don't involve the Peachpie compiler and I was just wondering what your ideas were?

Thank you.

Kevin

Compiler fails on resolving __dir__ inside a static variable?

So this file is part of the generated set of code composer install produces, it's the only file preventing compilation and an (out of the box) working composer autoloader.

The function isn't the problem the variables are.
Decomposing it even further the problem seems to be in resolving __DIR__, removing that also allows compilation to proceed. Is this a bug or a genuine limitation?

<?php

// autoload_static.php @generated by Composer

namespace Composer\Autoload;

class ComposerStaticInitace36e86701b84f0ecc3b67b1dcf079d
{
    public static $files = array (
        '578a43b5a178d809a159cf0ddb335d08' => __DIR__ . '/../..' . '/index.php',
    );

    public static $fallbackDirsPsr4 = array (
        0 => __DIR__ . '/../..' . '/src',
    );

    public static function getInitializer(ClassLoader $loader)
    {
        return \Closure::bind(function () use ($loader) {
            $loader->fallbackDirsPsr4 = ComposerStaticInitace36e86701b84f0ecc3b67b1dcf079d::$fallbackDirsPsr4;

        }, null, ClassLoader::class);
    }
}

No executable found matching command "dotnet-compile-php"

after pulling latest updates and attempting to run the basic web example with aspnetcore updated to 2.0.0 getting this error:

Peachpie PHP Compiler. 
Website ->C:\Users\jstac\git\newpeachweb\Website\bin\Debug\netcoreapp2.0\newpeachweb.dll

No executable found matching command "dotnet-compile-php"

im sure you dont officially support aspnetcore2.0 yet but any help would be awesome, im really waiting for aspnetcore2.0/php apps

CLR property read from single-typed alias results in invalid method call on PhpValue

See the following test case:

<?php
function test(DOMNodeList $x) {
  $y =& $x;
  echo $y->length;
}
test(new DOMNodeList);

It produces CIL similar to the following C# code:

public static void test(Context <ctx>, DOMNodeList x)
{
  PhpValue val = PhpValue.FromClass((object)x);
  PhpValue y2 = PhpValue.Null;
  y2 = PhpValue.Create(val.EnsureAlias());
  <ctx>.Echo(((DOMNodeList)y2).get_length());
}

get_length() is called directly on the PhpValue by this CIL:

IL_001c: ldloc.1
IL_001d: call instance int32 [Peachpie.Library.XmlDom]Peachpie.Library.XmlDom.DOMNodeList::get_length()

In the case of field or method access (e.g. $y->item(0)), a proper conversion is performed.

Cannot run example on ubuntu 17.10 nor debian 8/9

Hello,

I can't get work example with debian 8/9 nor ubuntu 17.10
I've done steps from https://www.microsoft.com/net/download/linux and from https://www.peachpie.io/getstarted?

Last step dotnet run returns error with following output:

/home/vagrant/.nuget/packages/peachpie.net.sdk/0.7.0-ci00318/build/Peachpie.NET.Core.Sdk.targets(148,5): error MSB3073: The command "dotnet compile-php @obj/Debug/netcoreapp1.0/compile-php-args.rsp" exited with code 131. [/home/vagrant/vagrant.msbuildproj]

The build failed. Please fix the build errors and run again.

Steps to reproduce - mkdir stretch; cd stretch; vagrant init debian/stretch64; vagrant ssh and follow steps from https://www.microsoft.com/net/learn/get-started/linuxdebian https://www.peachpie.io/getstarted?

Which linux distro is working? Thanks.

Wrong method override called

Test case:

<?php
class A implements Iterator {
  function rewind() { echo "A"; }
  function next() { }
  function valid() { }
  function key() { }
  function current() { }
}
class B extends A {
  function rewind() { echo "B"; }
}
function test(Iterator $i) {
  $i->rewind();
}
test(new B);

Expected result: B
Actual result: A

catch multiple type support

currently multiple types specified in catch block are not supported

try {}
catch (A|B $ex) {}

expected: compiles successfully
actual: compiler throws an unexpected value exception in EmitClassName

cURL

Hi there,

Just wondering on whether you have an estimate for implementation of cURL yet.

Clarify where to find .Net Core 1.1

Hello,

in your getting started guide you refer to the main landing page of .NET Core from Microsoft.
However that page does it's best to hide the download for the old/LTS 1.1 release ever since they released 2.0 in early august.

Maybe you could just point directly to the old releases section of the MS website from the Getting Started page at least until Peachpie drops its hard requirement for the 1.0.4 version of the SDK.

keys in list() are ignored

<?php
list("a" => $a, "b" => $b) = ["b" => 1,"a" => 2];
var_dump($a, $b);

expected: 2, 1
actual: null, null

Xamarin Support

What is the status on xamarin support? How can one test Peachpie in an xamarin android app?

`instanceof` to support right operand of type `object`

Consider the following test case:

<?php
class A {
  public function test($x) {
    if ($x instanceof $this) {
      echo "good";
    }
  }
}
(new A)->test(new A);

Expected result: good (the types of $x and $this are compared)
Actual result: empty

If we add the method public function __toString() { return "A"; }, it works, because $this is converted to A and this class is then found.

Executable optimization and dependencies

A couple of questions:

  1. Is it possible to minimize the size and number of DLL's that I have to include with my generated executable? With a minimal Hello World PHP script, compiled as Release, I found I needed the following:

83,456 helloworld.exe
851,456 Peachpie.Library.dll
19,456 Peachpie.Library.MsSql.dll
22,016 Peachpie.Library.MySql.dll
16,896 Peachpie.Library.Scripting.dll
78,336 Peachpie.Library.XmlDom.dll
371,712 Peachpie.Runtime.dll
33,256 System.Runtime.InteropServices.RuntimeInformation.dll
79,208 System.ValueTuple.dll

The total size being 1,555,792 bytes, which is pretty big for something that does nothing more than print Hello World. I understand that Peachpie needs to be as generic as possible, but I'd love to cut things down to the absolute minimum.

  1. Is it possible to integrate any required DLL's into "helloworld.exe" so I only need to distribute a single file as opposed to the executable and every accompanying DLL?

  2. Is it possible to use PHP extensions with Peachpie? I'm not sure what's already integrated, but assuming I needed to use something like "php_gd2" and it wasn't already integrated, how would I do that?

If it matters, I'm compiling entirely from the command line (no IDE/Visual Studio) using:

peach.exe /target:exe /debug- /optimize+ /out:helloworld.exe helloworld.php

Support for Custom Attributes

There is no custom attribute on classes, properties, variables, etc. in PHP.
Would it get implemented in Peachpie in future (useful for both-way .NET interop)?

error MSB4020

dotnet new -i Peachpie.Templates::*
dotnet new peachpie-console
dotnet restore
dotnet run

Gives me:
error MSB4020: The value "" of the "Project" attribute in element <Import> is invalid.

I have:
.NET Core SDK 1.1.4 (x64)

Calling anonymous function created in trait raises ArgumentException

Test case:

<?php
trait T {
  private $bar = "bar";

  public function getFn() {
    return function() { return $this->bar; };
  }
}
class C {
  use T;
}
echo (new C)->getFn()();

Expected result: bar
Actual result:

Unhandled Exception: System.ArgumentException: Cannot resolve method Pchp.Core.PhpValue anonymous@function(Closure) because the declaring type of the method handle T`1[TSelf] is generic. Explicitly provide the declaring type to GetMethodFromHandle.
   at System.Reflection.MethodBase.GetMethodFromHandle(RuntimeMethodHandle handle)
   at Pchp.Core.Reflection.PhpRoutineInfo.BindDelegate()
   at Pchp.Core.Reflection.PhpRoutineInfo.get_PhpCallable()
   ...

Is it possible to run PHP as a static file with .NET Core?

What I mean by this is, ASP.NET Core creates a folder named wwwroot and that's where the server's static files.

Can I store PHP files in there, and per request they just "work," like many webservers do.
If not, can I somehow add compatibility to this, or is there any alternatives that support this?

Class constant accessed from instance causes NullReferenceException

See the following usage of a PHP class constant:

<?php
class A
{
  const A_CONST = 42;
}
function test($a) {
  echo $a::A_CONST;
}
test(new A);

PHP returns 42, our runtime currently throws a runtime exception:

System.NullReferenceException occurred
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Peachpie.Runtime
  StackTrace:
   at Pchp.Core.Reflection.TypeMembersUtils.GetDeclaredConstant(PhpTypeInfo tinfo, String name) in C:\iolevel\peachpie\src\Peachpie.Runtime\Reflection\TypeMembersUtils.cs:line 412
   at Pchp.Core.Dynamic.BinderHelpers.BindClassConstant(PhpTypeInfo type, Type classCtx, String constName, Expression ctx) in C:\iolevel\peachpie\src\Peachpie.Runtime\Dynamic\BinderHelpers.cs:line 640
   at Pchp.Core.Dynamic.GetFieldBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args) in C:\iolevel\peachpie\src\Peachpie.Runtime\Dynamic\GetFieldBinder.cs:line 90
   at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at <Root>..\\..\\..\\..\\..\\..\\tests/constants.constants_003_php.test(Context <ctx>, PhpValue a) in C:\iolevel\peachpie\tests\constants\constants_003.php:line 9
   at <Root>..\\..\\..\\..\\..\\..\\tests/constants.constants_003_php.<Main>(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>) in C:\iolevel\peachpie\tests\constants\constants_003.php:line 12
   at <Root>..\\..\\..\\..\\..\\..\\tests/constants.constants_003_php.<Main>`0(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>)
   at Pchp.Core.Context.ScriptInfo.Evaluate(Context ctx, PhpArray locals, Object this, RuntimeTypeHandle self) in C:\iolevel\peachpie\src\Peachpie.Runtime\Context.ScriptsMap.cs:line 82
   at Peachpie.Library.Scripting.Script.Evaluate(Context ctx, PhpArray locals, Object this, RuntimeTypeHandle self) in C:\iolevel\peachpie\src\Peachpie.Library.Scripting\Context.Script.cs:line 278
   at ScriptsTest.ScriptsTest.CompileAndRun(String path) in C:\iolevel\peachpie\src\Tests\Peachpie.ScriptTests\ScriptsTest.cs:line 80
   at ScriptsTest.ScriptsTest.ScriptRunTest(String dir, String fname) in C:\iolevel\peachpie\src\Tests\Peachpie.ScriptTests\ScriptsTest.cs:line 35

It occurs when tinfo.Type.GetInterfaces() is accessed in TypeMembersUtils.GetDeclaredConstant() (tinfo is null).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.