From 73bb909baef9ee5f3933850a75dc107e654185cf Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 1 May 2014 14:37:58 +1200 Subject: [PATCH] [PHP] The generated __isset() method now returns true for read-only properties. --- CHANGES.current | 3 ++ Examples/test-suite/php/arrays_runme.php | 1 + Source/Modules/php.cxx | 43 ++++++++++++------------ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 11682c9dd..826b1a2c5 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.1 (in progress) =========================== +2014-05-01: olly + [PHP] The generated __isset() method now returns true for read-only properties. + 2014-04-08: wsfulton SF Bug #1366 - Remove duplicate declarations of strtoimax and strtoumax in inttypes.i diff --git a/Examples/test-suite/php/arrays_runme.php b/Examples/test-suite/php/arrays_runme.php index 23490e61e..ae17d05e7 100644 --- a/Examples/test-suite/php/arrays_runme.php +++ b/Examples/test-suite/php/arrays_runme.php @@ -12,6 +12,7 @@ check::classname(simplestruct,$ss); $as=new arraystruct(); $as->array_c="abc"; check::equal($as->array_c,"a",'$as->array_c=="a"'); +check::equal(isset($as->array_const_i),TRUE,'isset($as->array_const_i)'); check::done(); ?> diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 86e1274a8..b07c82d3b 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2054,7 +2054,6 @@ done: // Write property SET handlers ki = First(shadow_set_vars); - if (ki.key) { // This class has setters. Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n"); @@ -2077,17 +2076,6 @@ done: Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); } Printf(s_phpclasses, "\t}\n"); - - /* Create __isset for PHP 5.1 and later; PHP 5.0 will just ignore it. */ - Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); - Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_set')) return true;\n", shadow_classname); - Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); - if (baseclass) { - Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass); - } else { - Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); - } - Printf(s_phpclasses, "\t}\n"); } else { Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_alter_newobject($this->%s,$value);\n", module, SWIG_PTR); @@ -2097,18 +2085,10 @@ done: Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); } Printf(s_phpclasses, "\t}\n"); - Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); - Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); - if (baseclass) { - Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass); - } else { - Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); - } - Printf(s_phpclasses, "\t}\n"); } + // Write property GET handlers ki = First(shadow_get_vars); - if (ki.key) { // This class has getters. Printf(s_phpclasses, "\n\tfunction __get($var) {\n"); @@ -2144,6 +2124,19 @@ done: Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA); } Printf(s_phpclasses, "\t}\n"); + + /* Create __isset for PHP 5.1 and later; PHP 5.0 will just ignore it. */ + /* __isset() should return true for read-only properties, so check for + * *_get() not *_set(). */ + Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); + Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_get')) return true;\n", shadow_classname); + Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); + if (baseclass) { + Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass); + } else { + Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); + } + Printf(s_phpclasses, "\t}\n"); } else { Printf(s_phpclasses, "\n\tfunction __get($var) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); @@ -2153,6 +2146,14 @@ done: Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA); } Printf(s_phpclasses, "\t}\n"); + Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); + Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); + if (baseclass) { + Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass); + } else { + Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); + } + Printf(s_phpclasses, "\t}\n"); } if (!class_has_ctor) {