Skip to content

Commit

Permalink
Added: "foo" method to "MyClass" class
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickallaert authored and Patrick Allaert committed May 13, 2015
1 parent dca1a1f commit 739f844
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
31 changes: 30 additions & 1 deletion myext.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,42 @@ ZEND_GET_MODULE(myext)

zend_class_entry *ce_MyClass;

ZEND_BEGIN_ARG_INFO_EX(arginfo_myclass_foo, 0, 0, 1)
ZEND_ARG_INFO(0, number)
ZEND_ARG_INFO(1, string)
ZEND_END_ARG_INFO()

static zend_function_entry myclass_class_functions[] = {
PHP_ME( MyClass, foo, arginfo_myclass_foo, ZEND_ACC_PUBLIC )
PHP_FE_END
};

PHP_MINIT_FUNCTION(myext)
{
zend_class_entry ce;

INIT_CLASS_ENTRY(ce, "MyClass", NULL);
INIT_CLASS_ENTRY(ce, "MyClass", myclass_class_functions);
ce.create_object = NULL;
ce_MyClass = zend_register_internal_class(&ce TSRMLS_CC);

return SUCCESS;
}

PHP_METHOD(MyClass, foo)
{
char *string;
size_t string_len;
#if PHP_VERSION_ID >= 70000
zend_long number;
#else
long number;
#endif

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &number, &string, &string_len) == FAILURE)
{
return;
}

php_printf("Number: %ld, String: ", number);
PHPWRITE(string, string_len);
}
3 changes: 2 additions & 1 deletion myext.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$object = new MyClass;
var_dump( $object );
$string = "Is this a real answer?";
$object->foo(42, $string);
1 change: 1 addition & 0 deletions php_myext.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PHP_MINIT_FUNCTION(myext);
PHP_METHOD(MyClass, foo);

0 comments on commit 739f844

Please sign in to comment.