php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41078 Its not possible to call Static dotNet Classes with dotnet
Submitted: 2007-04-13 17:45 UTC Modified: 2020-02-08 11:30 UTC
Votes:17
Avg. Score:4.2 ± 1.0
Reproduced:15 of 16 (93.8%)
Same Version:2 (13.3%)
Same OS:2 (13.3%)
From: mail at brutos dot org Assigned:
Status: Suspended Package: COM related
PHP Version: Next Minor Version OS: Windows Vista Ultimate x86
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mail at brutos dot org
New email:
PHP Version: OS:

 

 [2007-04-13 17:45 UTC] mail at brutos dot org
Description:
------------
You can call non static classes like
System.Collections.Stack
or
System.Text.StringBuilder

But no static classes like System.Console.

Reproduce code:
---------------
<?php
  $console = new DOTNET("mscorlib", "System.Console");
  $console->WriteLine("Hello World!");
?>

Expected result:
----------------
Hello World!

Actual result:
--------------
Fatal error: Uncaught exception 'com_exception' with message 'Failed to instanti
ate .Net object [CreateInstance] [0x80131513] ' in C:\Users\Brutos\Desktop\test.php:2
Stack trace:
#0 C:\Users\Brutos\Desktop\test.php(2): dotnet->dotnet('mscorlib', 'System.Console')
#1 {main}
  thrown in C:\Users\Brutos\Desktop\test.php on line 2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-09 23:51 UTC] ben at nullcreations dot net
Reproduced in Windows 7 using php 5.4.9
 [2013-02-20 13:47 UTC] user at kkdf2 dot sakura dot ne dot jp
It needs help of the wrapper class to be done.

---
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace StaticWrapper {
    [ComVisible(true), Guid("1b74f314-1536-4cbb-8e01-752a17b1079f")]
    public class Class1 {
        public Object Call(String typeName, String methodName, Object[] args) {
            return Type.GetType(typeName, true).InvokeMember(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, args);
        }
        public Object GetField(String typeName, String methodName) {
            return Type.GetType(typeName, true).InvokeMember(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField, null, null, new Object[0]);
        }
        public Object SetField(String typeName, String methodName, Object arg) {
            return Type.GetType(typeName, true).InvokeMember(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.SetField, null, null, new Object[] { arg });
        }
        public Object GetProperty(String typeName, String methodName) {
            return Type.GetType(typeName, true).InvokeMember(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty, null, null, new Object[0]);
        }
        public Object SetProperty(String typeName, String methodName, Object arg) {
            return Type.GetType(typeName, true).InvokeMember(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.SetProperty, null, null, new Object[] { arg });
        }
    }
}
---

example to use
---
<?php
$x = new COM("StaticWrapper.Class1");
print $x->Call("System.Console, mscorlib", "WriteLine", array("Hello {0}", "php"));
print "\n";
print $x->GetField("System.Decimal", "MaxValue");
print "\n";
print $x->GetProperty("System.DateTime", "Now");
print "\n";

//$x->SetField("System.String", "Empty", "");
//$x->SetProperty("System.Net.ServicePointManager, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "MaxServicePoints", 0);

?>
---
 [2013-12-13 07:48 UTC] wez@php.net
-Status: Assigned +Status: Open -Assigned To: wez +Assigned To:
 [2015-07-18 14:21 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2019-10-18 11:49 UTC] girgias@php.net
-PHP Version: 5CVS-2007-04-13 (snap) +PHP Version: Next Minor Version -Assigned To: +Assigned To: cmb
 [2019-10-18 11:49 UTC] girgias@php.net
Assigning to cmb for review as he's the new maintainer for COM.
 [2019-12-02 23:59 UTC] cmb@php.net
-Status: Assigned +Status: Suspended -Assigned To: cmb +Assigned To:
 [2019-12-02 23:59 UTC] cmb@php.net
Indeed, COM does not support static methods.  While there are
certainly ways to overcome this limitation, the details need to be
discussed on the internals@ mailing list[1].  Anybody is welcome
to start that discussion.  For the time being, I'm suspending this
ticket.

[1] <https://www.php.net/mailing-lists.php#internals>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 06:01:29 2024 UTC