Hi,

It seems something has changed recently regarding referencing
constants that has broken my extension and I'm trying to figure out
exactly what the right thing to do is.

When passing a string constant to an extension function, within the
extension I have been saving that string directly for possible
retrieval later (see code below).

This has worked fine but it seems with recent releases of PHP (5.2.5
is what I'm testing with) the memory the string points to gets
clobbered after the function returns. Meaning when I retrieve the
value later it is garbage data.

I suppose thinking a string parameter would be valid after the call
was a bold assumption but it worked.

Has something changed regarding parameters that are constants?

Or was my code always broken and it's just a coincidence that I'm
seeing corrupted values now?

How can I convert a string constant to a value that I can save internally?

Must I simply copy the string always?

Does zend_get_constant help?

Mike

PHP_FUNCTION(foo_status)
{
    zval *r;
    char *s = "";
    int slen;
    struct foo *foo = NULL;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|s!",
                &r, &s, &slen) == FAILURE) {
        RETURN_FALSE;
    }

    if (r)
        foo = (struct foo *)zend_fetch_resource(&r TSRMLS_CC,
                -1, "foo", NULL, 1, le_foo);

    if (ZEND_NUM_ARGS() > 1) {
        foo_status(foo) = s; // save the status for possible retrieval later
    }

    RETURN_STRING(foo_status(foo), 1);
}

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to