From e59dbf74f2c4fe44ae8fdadd50070b42ee68d4e6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 25 Aug 2007 13:11:25 +0000 Subject: [PATCH] [PHP5] Generate __isset() methods for setters for PHP 5.1 and later. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9913 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/php4.cxx | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index ab4a363c7..8ca71982a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 1.3.32 (in progress) ============================ +08/25/2007: olly + [PHP5] Generate __isset() methods for setters for PHP 5.1 and later. + 08/20/2007: wsfulton [Java C#] Fix director bug #1776651 reported by Jorgen Tjerno which occured when the director class name is the same as the start of some other symbols used within diff --git a/Source/Modules/php4.cxx b/Source/Modules/php4.cxx index c2908776d..b20918fdd 100644 --- a/Source/Modules/php4.cxx +++ b/Source/Modules/php4.cxx @@ -27,12 +27,9 @@ * This is an optimisation - we could handle this case using a PHP * default value, but currently we treat it as we would for a default * value which is a compound C++ expression (i.e. as if we had a - * a method with two overloaded forms instead of a single method with + * method with two overloaded forms instead of a single method with * a default parameter value). * - * Create __isset method for PHP 5.1 and later (we can probably just - * always generate as PHP 5.0 should just ignore it). - * * Long term: * * Option to generate code to work with PHP4 instead ("public $_cPtr;" -> @@ -2372,7 +2369,26 @@ public: Printf(s_phpclasses, "\t\tif (function_exists($func)) call_user_func($func,$this->%s,$value);\n", SWIG_PTR); } Printf(s_phpclasses, "\t}\n"); - /* FIXME: also create __isset for PHP 5.1 and later? */ + + /* Create __isset for PHP 5.1 and later; PHP 5.0 will just ignore it. */ + Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); + // FIXME: tune this threshold, but it should probably be different to + // that for __set() and __get() as we don't need to call_user_func() + // here... + if (Len(shadow_set_vars) == 1) { + // Only one setter, so just check the name. + Printf(s_phpclasses, "\t\treturn "); + while (ki.key) { + key = ki.key; + Printf(s_phpclasses, "$var == '%s'", ki.key); + ki = Next(ki); + if (ki.key) Printf(s_phpclasses, " || "); + } + Printf(s_phpclasses, ";\n"); + } else { + Printf(s_phpclasses, "\t\treturn function_exists('%s_'.$var.'_set');\n", shadow_classname); + } + Printf(s_phpclasses, "\t}\n"); } // Write property GET handlers ki = First(shadow_get_vars);