Olly Betts wrote:
>On 2006-02-17, Marcelo Matus <mmatus@...> wrote:
>>If you have an unreported issue with 1.3.28, please try to
>>submit a bug report or a note into the mailing list quick,
>>since William wants to wrap the latest fixes in a pure "fix release"
>>version, 1.3.29, soon.
>There's an issue with overloaded functions in PHP. The problem is that
>if you have a function which can take a number or a string, then the
>"is this a number" test happens first, and accepts any of IS_LONG,
>IS_DOUBLE, or IS_STRING (PHP types), so the string version of the
>function never gets a look-in.
>I think the sane approach is to not check for string when wanting a
>number - in PHP you can write (int)$value if you want to allow a
>numeric string (such as "2") to be passed (and you can write
>(string)$value to force interpretation as a string). I'm currently
>working on a patch to SWIG along these lines - I'll post it when I'm
>done (probably tomorrow).
also, for the next dev-release, 1.3.30 or so, you can take a look at the
cast-rank overloading mechanism used in perl and optionally in python
(see the CHANGES.readme). In short, you can accept a 'int' value from
a string, but with a different cast order, then the overload dispatcher,
having for example:
can properly dispatch the calls, ie:
bar(1) -> bar(int)
bar("1") -> bar(int)
bar(1.5) -> bar(double)
bar("1.5") -> bar(double)
bar(1.0) -> bar(double)
foo(1) -> foo(int)
foo("1") -> foo(char *) // cast rank dispatch the string properly
foo(1.0) -> foo(int) // fine to convert to 'int'
foo(1.5) -> **error**
>The other alternative seems to be to somehow accept IS_STRING for a
>number only if there's no string overload. I'm not sure how you'd
>achieve that within SWIG's precedence system though. Perhaps setting
>the string precedence higher than numbers for PHP would work, but I
>fear that would cause other problems.
>This has only recently become an issue (in 1.3.27 I think) because
>prior to that SWIG/PHP didn't support overloading.
>This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
>for problems? Stop! Download the new AJAX search engine that makes
>searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
>Swig-devel mailing list