Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jan 15, 2024
1 parent 7a2b74a commit 00d4918
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/class/animal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import abc


class Animal(abc.ABC):
def __init__(self, name, age):
self.name = name
self.age = age

def speak(self, name):
print("Animal speak")
pass
20 changes: 20 additions & 0 deletions examples/class/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

PyCore::import('sys')->path->append('.');

$types = PyCore::import('types');

$Animal = PyCore::import('animal')->Animal;
$Dog = $types->new_class(
'Dog',
(PyCore::tuple([$Animal])),
[]
);

$dog = $Dog('', 1);
$dog->speak = $types->MethodType(function ($self, $name) use ($Animal, $Dog) {
PyCore::print("My name is {$self->name}, age is {$self->age}");
$super = PyCore::super($Dog, $self);
$super->speak('dog');
}, $dog);
$dog->speak('哈士奇');

0 comments on commit 00d4918

Please sign in to comment.