Parameter type errors and some other cases in SWIG-generated wrappers
now throw a PHP exception, which is how PHP's native parameter handling
deals with similar situations.
See #2014, but not closing yet as there may be more cases to convert.
Most pre-defined interfaces are accessible via zend_class_entry*
variables declared in the PHP C API - we can use these to add
an interface at MINIT time (rather than having to wait until RINIT to
look up by name) by having a mapping from PHP interface name to them.
This will also be a little faster than looking up by name.
Closes#2013
The underlying wrapper function is now always named using
ZEND_NAMED_FUNCTION even if it's a method (in PHP a function and
a method only differ in how they're used).
Eliminate redundant and unused includes.
Only include the minimum headers needed before the PHP_MAJOR_VERSION
check in case future PHP versions remove some of the headers we
include.
This has been in the code for a really long time, and doesn't seem
to be required now. It's not documented by PHP as something we
need to do, and the value seems to always be NULL at this point
already.
With modern PHP it only works with the CLI version of PHP, so it's
better to direct users to load the extension via "extension=" in
php.ini.
Suggested by ferdynator in #1529.
These were officially deprecated in 2001, and attempts to use them have
resulted in a warning (including a pointer to what to update them to)
for most if not all of that time.
Fixes#1984
A PHP exception now gets translated to a C++ exception to skips over C++
code to get back to PHP, avoiding the need to gate every directorout
typemap on EG(exception).
Previously we checked for a <varname>_get() method instead, but that
will misfire for an method actually called foo_get() in the C++ API
being wrapped.
This isn't really workable since PHP doesn't support intercepting
accesses to global variables (nor to static class properties, so
we can't wrap C/C++ global variables that way either).
The _get() and _set() function wrappers actually work and have
been generated for a very long time.
These were deprecated nearly 20 years ago and attempts to use them
have generated a deprecation warning for most of that time.
Addresses #1984 for PHP.
These were added as part of the changes to add director support for
PHP, but have never actually been used by anything SWIG generates,
and they aren't documented so shouldn't be used externally.
Removing these exposed a bug in the arginfo generation where we emitted
a ZEND_ARG_INFO for a varargs "parameter", which this commit also fixes.
Use zend_call_known_instance_method() instead of call_user_function(),
since this way PHP seems to know that context of the call is from within
the same object.
Fixes testcases director_nested and director_protected which were giving
errors for PHP 8 and warnings for PHP 7.
These names lack a "SWIG_" prefix to help prevent collisions with code
being wrapped, but they're each only used in one place so just inline
them there.
These are all the same, and the NULL check performed is done inside
zend_objects_destroy_object() anyway, so we can just set the dtor
to zend_objects_destroy_object (which is what in-tree PHP extensions
do.)
This was used to store custom properties, but we can just ask the PHP
object to store them like it normally would, after checking for our
custom pseudo-properties.
getThis(z) checks that z is a PHP object and returns ZEND_THIS if it
is, and NULL otherwise. In all our uses we know that z is a PHP object
(and we'd try to dereference NULL if it were returned!)
It existed to work around const-correctness issues in older versions of
PHP's C API. It's conceivable user code might be using it, but unlikely
and the switch to creating classes via the API is a natural time for a
compatibility break.
This PR removes the closing `?>` PHP tag from generated files. [PSR-2](https://www.php-fig.org/psr/psr-2/) states:
> The closing `?>` tag MUST be omitted from files containing only PHP.
A problem might occur if files with any character after the closing tag are used with `include` or `require`. It might trigger an output and disallow HTTP header manipulation. See the popular [_headers already sent_](https://stackoverflow.com/a/8028987/1847340) debate on SO.
Finally removed support for %pragma(php4) which was deprecated back in
2008. The replacement is %pragma(php), which has been supported since
at least 2005.
PHP5 is no longer actively supported by the PHP developers and security
support for it ends completely at the end of 2018, so it doesn't make
sense to include support for it in the upcoming SWIG 4.0.0 release.
See #701.
- Fixes generation of director method declarations containing C++11 ref-qualifiers.
- Fixes generation of director method declarations returning more complex types such
as const ref pointers.
- Rewrite Swig_method_call to use more up to date code in the core.
The directorin typemaps will now generate a temporary variable
(specified after the type), such as:
%typemap(directorin) MyType (MyType *temp) { ... use temp ... }
The shared_ptr director typemaps have been fixed for use in functions
that take more than one parameter.