[php] Add php:allowdynamicproperties feature

This follows PHP 8.2 deprecating dynamic features.

The new feature also provides a clean way to fix the remaining PHP
test case failure under PHP 8.2.
This commit is contained in:
Olly Betts 2022-09-29 18:14:23 +13:00
commit 9a4dea06c8
4 changed files with 86 additions and 4 deletions

View file

@ -30,6 +30,7 @@
<li><a href="#Php_nn2_6_3">Static Member Variables</a>
<li><a href="#Php_nn2_6_4">Static Member Functions</a>
<li><a href="#Php_nn2_6_5">Specifying Implemented Interfaces</a>
<li><a href="#Php_nn2_6_6">Dynamic Properties</a>
</ul>
<li><a href="#Php_nn2_7">PHP Pragmas, Startup and Shutdown code</a>
</ul>
@ -843,6 +844,53 @@ so:
If there are multiple interfaces, just list them separated by commas.
</p>
<H4><a name="Php_nn2_6_6">32.2.6.6 Dynamic Properties</a></H4>
<p>
Historically PHP has supported dynamic class properties and SWIG
has implemented them too (because we implement the magic <tt>__get()</tt>,
<tt>__set()</tt> and <tt>__isset()</tt> methods we need to include explicit
handling).
</p>
<p>
PHP 8.2 <a
href="https://wiki.php.net/rfc/deprecate_dynamic_properties">deprecates
dynamic class properties</a> - initially they'll warn, and apparently they'll
not work by default in PHP 9.0.
</p>
<p>
In PHP code dynamic properties can be enabled for a class by
marking that class with the attribute <tt>#[AllowDynamicProperties]</tt>.
</p>
<p>
To follow this PHP change, as of SWIG 4.1.0 you now need enable dynamic
properties for any classes you want to support them. To enable for class
<tt>Foo</tt>:
</p>
<div class="code"><pre>
%feature("php:allowdynamicproperties", 1) Foo;
</pre></div>
<p>
or to enable them for all wrapped classes:
</p>
<div class="code"><pre>
%feature("php:allowdynamicproperties", 1);
</pre></div>
<p>
Note that unknown features are ignored, so you can add use these
unconditionally in your interface file and it'll work with older SWIG too.
</p>
<H3><a name="Php_nn2_7">32.2.7 PHP Pragmas, Startup and Shutdown code</a></H3>