#937 [php] Inconsistent behavior of null/NULL

closed-fixed
Olly Betts
php (58)
5
2008-09-18
2008-07-23
Martin Mares
No

When a C function returning a `char *' returns a NULL pointer, it is translated to the null value in PHP. However, in the opposite direction the null value gets translated to an empty string.

This is both inconvenient and inconsistent with the handling of NULL in the generated wrappers for other languages (e.g., in Python).

I suggest modifying the default input typemap as follows:

%typemap(in) char * {
if ((*$input)->type == IS_NULL) {
$1 = NULL;
} else {
convert_to_string_ex($input);
$1 = Z_STRVAL_PP($input);
}
}

Discussion

  • Olly Betts
    Olly Betts
    2008-07-27

    Logged In: YES
    user_id=14972
    Originator: NO

    Yes, this doesn't seem right. Thanks for reporting it.

    One slight issue is that existing user interface files might rely on this misfeature, so we really ought to document clearly how to retain it should you need to (with a custom typemap).

    Feel free to work on a patch. Otherwise I'll take a look when I'm less busy with other things.

     
  • Olly Betts
    Olly Betts
    2008-07-27

    • assigned_to: kruland --> olly
    • summary: Inconsistent behavior of null/NULL --> [php] Inconsistent behavior of null/NULL
     
  • Olly Betts
    Olly Betts
    2008-09-18

    Fixed in SVN HEAD.

     
  • Olly Betts
    Olly Betts
    2008-09-18

    • status: open --> closed-fixed