Hi,
This is my first extension I'm working on. I'm trying to make a class
available to the user space with 1 private property that is an array.
I posted my source and question here
http://stackoverflow.com/questions/10052739/how-do-you-create-a-private-property-as-an-array-in-a-class-within-php-ext
I think I'm going in the right direction. Can someone please help?
thank you
Hi,
This is my first extension I'm working on. I'm trying to make a class
available to the user space with 1 private property that is an array.
The first question is: Why? - Why add the overhead of creating such an
array if it is private? In most cases it is better to extend the
zend_object in C (struct my_object { zend_object inner; type
some_data;}) to hold private data. If you want to show it in var_dump or
a debugger you could implement a debug_info hook.
johannes
Hi Johannes,
Yes I just found out that I should extend instead of the approach I was
thinking about.
So I created this:
typedef struct _foo_object {
zend_object std;
zval *array;
int size;
} foo_object;
So the question is how do I correctly pass foo_object around so that I can
manipulate *array ? Having a private variable would mean calling getThis()
and handling it that way would be trivial.
Are there any examples I could see? I'm using the slides from your
presentation in 2009 to help me.
thanks
On Sat, Apr 7, 2012 at 2:27 PM, Johannes Schlüter johannes@schlueters.dewrote:
Hi,
This is my first extension I'm working on. I'm trying to make a class
available to the user space with 1 private property that is an array.The first question is: Why? - Why add the overhead of creating such an
array if it is private? In most cases it is better to extend the
zend_object in C (struct my_object { zend_object inner; type
some_data;}) to hold private data. If you want to show it in var_dump or
a debugger you could implement a debug_info hook.johannes
Here's what I have so far:
typedef struct _foo_class_object {
zend_object std;
zval *elements;
int size;
} foo_class_object;
static foo_class_object *foo_class_object_ptr;
static zend_class_entry *foo_class_ptr;
ZEND_METHOD(foo_class, __construct) {
foo_class_object_ptr = (foo_class_object
*)zend_object_store_get_object(getThis() TSRMLS_CC);
array_init(foo_class_object_ptr->elements);
}
ZEND_METHOD(foo_class, add) {
zval *this = getThis();
zval *item;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &item) ==
FAILURE) {
RETURN_FALSE;
}
add_next_index_zval(foo_class_object_ptr->elements, item);
RETURN_TRUE;
}
However, this doesn't work. when you call FooClass::add it causes a
segfault. I'm sure I'm abusing something :)
thx
On Sat, Apr 7, 2012 at 2:38 PM, Matthew Hernandez proxilabs@gmail.comwrote:
Hi Johannes,
Yes I just found out that I should extend instead of the approach I was
thinking about.So I created this:
typedef struct _foo_object {
zend_object std;
zval *array;
int size;
} foo_object;So the question is how do I correctly pass foo_object around so that I can
manipulate *array ? Having a private variable would mean calling getThis()
and handling it that way would be trivial.Are there any examples I could see? I'm using the slides from your
presentation in 2009 to help me.thanks
On Sat, Apr 7, 2012 at 2:27 PM, Johannes Schlüter johannes@schlueters.dewrote:
Hi,
This is my first extension I'm working on. I'm trying to make a class
available to the user space with 1 private property that is an array.The first question is: Why? - Why add the overhead of creating such an
array if it is private? In most cases it is better to extend the
zend_object in C (struct my_object { zend_object inner; type
some_data;}) to hold private data. If you want to show it in var_dump or
a debugger you could implement a debug_info hook.johannes
hi:
You can refer to ext spl array
Thanks
Sent from my iPhone
在 2012-4-8,7:12,Matthew Hernandez proxilabs@gmail.com 写道:
Here's what I have so far:
typedef struct _foo_class_object {
zend_object std;
zval *elements;
int size;
} foo_class_object;static foo_class_object *foo_class_object_ptr;
static zend_class_entry *foo_class_ptr;ZEND_METHOD(foo_class, __construct) {
foo_class_object_ptr = (foo_class_object
*)zend_object_store_get_object(getThis() TSRMLS_CC);array_init(foo_class_object_ptr->elements);
}ZEND_METHOD(foo_class, add) {
zval *this = getThis();
zval *item;if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &item) ==
FAILURE) {
RETURN_FALSE;
}add_next_index_zval(foo_class_object_ptr->elements, item);
RETURN_TRUE;
}However, this doesn't work. when you call FooClass::add it causes a
segfault. I'm sure I'm abusing something :)thx
On Sat, Apr 7, 2012 at 2:38 PM, Matthew Hernandez proxilabs@gmail.comwrote:
Hi Johannes,
Yes I just found out that I should extend instead of the approach I was
thinking about.So I created this:
typedef struct _foo_object {
zend_object std;
zval *array;
int size;
} foo_object;So the question is how do I correctly pass foo_object around so that I can
manipulate *array ? Having a private variable would mean calling getThis()
and handling it that way would be trivial.Are there any examples I could see? I'm using the slides from your
presentation in 2009 to help me.thanks
On Sat, Apr 7, 2012 at 2:27 PM, Johannes Schlüter johannes@schlueters.dewrote:
Hi,
This is my first extension I'm working on. I'm trying to make a class
available to the user space with 1 private property that is an array.The first question is: Why? - Why add the overhead of creating such an
array if it is private? In most cases it is better to extend the
zend_object in C (struct my_object { zend_object inner; type
some_data;}) to hold private data. If you want to show it in var_dump or
a debugger you could implement a debug_info hook.johannes
Thanks.
How can I valgrind my extension? Google isn't bringing up many php
extension topics :/
I can't figure out why I keep getting a seg fault:
typedef struct _foo_object {
zend_object std;
zval *elements;
} foo_object;
static foo_object *foo_object_ptr;
PHP_MINIT_FUNCTION(foo_class)
{
foo_object_ptr = emalloc(sizeof(foo_object));
MAKE_STD_ZVAL(foo_object_ptr->elements);
array_init(foo_object_ptr->elements);
return SUCCESS;
}
MAKE_STD_ZVAL(foo_object_ptr->elements);
array_init(foo_object_ptr->elements);
These two lines are causing the seg fault, I'm trying to understand why.
hi:
You can refer to ext spl arrayThanks
Sent from my iPhone
在 2012-4-8,7:12,Matthew Hernandez proxilabs@gmail.com 写道:
Here's what I have so far:
typedef struct _foo_class_object {
zend_object std;
zval *elements;
int size;
} foo_class_object;static foo_class_object *foo_class_object_ptr;
static zend_class_entry *foo_class_ptr;ZEND_METHOD(foo_class, __construct) {
foo_class_object_ptr = (foo_class_object
*)zend_object_store_get_object(getThis() TSRMLS_CC);array_init(foo_class_object_ptr->elements);
}ZEND_METHOD(foo_class, add) {
zval *this = getThis();
zval *item;if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &item) ==
FAILURE) {
RETURN_FALSE;
}add_next_index_zval(foo_class_object_ptr->elements, item);
RETURN_TRUE;
}However, this doesn't work. when you call FooClass::add it causes a
segfault. I'm sure I'm abusing something :)thx
On Sat, Apr 7, 2012 at 2:38 PM, Matthew Hernandez <proxilabs@gmail.com
wrote:Hi Johannes,
Yes I just found out that I should extend instead of the approach I was
thinking about.So I created this:
typedef struct _foo_object {
zend_object std;
zval *array;
int size;
} foo_object;So the question is how do I correctly pass foo_object around so that I
can
manipulate *array ? Having a private variable would mean calling
getThis()
and handling it that way would be trivial.Are there any examples I could see? I'm using the slides from your
presentation in 2009 to help me.thanks
On Sat, Apr 7, 2012 at 2:27 PM, Johannes Schlüter <
johannes@schlueters.de>wrote:Hi,
This is my first extension I'm working on. I'm trying to make a class
available to the user space with 1 private property that is an array.The first question is: Why? - Why add the overhead of creating such an
array if it is private? In most cases it is better to extend the
zend_object in C (struct my_object { zend_object inner; type
some_data;}) to hold private data. If you want to show it in var_dump
or
a debugger you could implement a debug_info hook.johannes
How can I valgrind my extension? Google isn't bringing up many php
extension topics :/
On the shell:
export USE_ZEND_ALLOC=0
export ZEND_DONT_UNLOAD_MODULES=1
valgrind php -dextension=yourextension.so yourscript.php
See for some more info here:
http://derickrethans.nl/valgrinding-shared-modules.html
I can't figure out why I keep getting a seg fault:
typedef struct _foo_object {
zend_object std;
zval *elements;
} foo_object;static foo_object *foo_object_ptr;
You really want to avoid real globals like this though, as it makes
things not thread-safe.
Also, please don't top-reply on this list.
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
How can I valgrind my extension? Google isn't bringing up many php
extension topics :/On the shell:
export USE_ZEND_ALLOC=0
export ZEND_DONT_UNLOAD_MODULES=1
valgrind php -dextension=yourextension.so yourscript.phpSee for some more info here:
http://derickrethans.nl/valgrinding-shared-modules.html
thanks, this solved the seg fault issue in no time.
I can't figure out why I keep getting a seg fault:
typedef struct _foo_object {
zend_object std;
zval *elements;
} foo_object;static foo_object *foo_object_ptr;
You really want to avoid real globals like this though, as it makes
things not thread-safe.
thanks, I'll avoid doing it like this.
Which reminds me. Would you happen to have a "best practices" for
php-extension development that I could reference? I've found a few articles
around, mostly out dated.
Also, please don't top-reply on this list.
sorry.
cheers,
Derick--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug