I have the following C method in a library which I am trying use with PHP. The method returns an error code and returns the value of an integer passed as a pointer:


int getMyAge(int *age)


  if able to find age


     *age = // value;

     return 0;



    return error_code;



In PHP I would like the SWIG-generated wrapper to return FALSE when an error occurs and the age as an integer when successful. PHP models this in other APIs by returning the “mixed” type.  Is there a way to do this with custom typemaps in SWIG?


I am able to use simple typemaps in SWIG to get the SWIG-generated wrapper to return an array which contains the error code and age. I know I could write a PHP function around this which provides the behavior I want. I was wondering if there is a way to do this with typemaps or other SWIG capabilities without the need for wrapper functions.


I am using SWIG 3.0.0 to expose this C method to PHP (ver. 5.3.10).


Thanks in advance for any help you can provide.