从python类创建一个php对象

时间:2017-06-07 11:44:43

标签: php python class object

有没有办法可以从php object创建python class? 我发现example

python类:

# module.py
class TestClass:
    def __init__(self, foo):
        self.foo = foo

    def returnInt(self):
        return 1113

    def test(self, a, b = 'str'):
        return "a = %d, b = %s" % (a, b)

    def returnMe(self):
        return self

    def returnTuple(self):
        return (1, "two", 3.0)

    def returnList(self):
        return [1, "two", 3.0]

    def returnDict(self):
        d = {}
        d['one'] = 1
        d['two'] = 2
        d['three'] = 3
        return d

    def p(self, var):
        print var

php脚本:

<?php
$p = new Python('module', 'TestClass', array(435));
print $p->returnInt() . "\n";
print $p->test(1, 'bar') . "\n";

print $p->foo . "\n";
$p->foo = 987;
print $p->foo . "\n";

# $copy points to the same object
$copy = $p->returnMe();
print $copy->foo . "\n";
$p->foo = 987;
print $copy->foo . "\n";
?>

但它没有用。

我收到此错误消息:

  

Class&#39; Python&#39;在C:\ wamp \ www \ MDASA \ public \ tst.php

中找不到

所以我的问题是:如果有一种方法可以从python类创建一个php对象,那么代码是正确的还是不是?

0 个答案:

没有答案