summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/src/slice2php/Main.cpp111
-rw-r--r--php/src/php/Config.h12
-rw-r--r--php/src/php/Connection.cpp2
-rw-r--r--php/src/php/Endpoint.cpp2
-rw-r--r--php/src/php/Logger.cpp2
-rw-r--r--php/src/php/Properties.cpp2
-rw-r--r--php/src/php/Proxy.cpp2
-rw-r--r--php/test/Ice/checksum/Client.php4
-rw-r--r--php/test/TestHelper.php2
9 files changed, 110 insertions, 29 deletions
diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp
index 89693422fc6..4b70f734ca4 100644
--- a/cpp/src/slice2php/Main.cpp
+++ b/cpp/src/slice2php/Main.cpp
@@ -84,6 +84,10 @@ private:
void startNamespace(const ContainedPtr&);
void endNamespace();
+ void writeClassDef(const ClassDefPtr&, bool);
+ void writeException(const ExceptionPtr&, bool);
+ void writeStruct(const StructPtr&, bool);
+
//
// Return the PHP name for the given Slice type. When using namespaces,
// this name is a relative (unqualified) name, otherwise this name is the
@@ -192,6 +196,32 @@ bool
CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
{
string scoped = p->scoped();
+
+ startNamespace(p);
+
+ _out << sp << nl << "if (PHP_VERSION_ID < 80200)";
+ _out << sb;
+ writeClassDef(p, false);
+ _out << eb;
+ _out << nl << "else";
+ _out << sb;
+ writeClassDef(p, true);
+ _out << eb;
+
+ endNamespace();
+
+ if(_classHistory.count(scoped) == 0)
+ {
+ _classHistory.insert(scoped); // Avoid redundant declarations.
+ }
+
+ return false;
+}
+
+void
+CodeVisitor::writeClassDef(const ClassDefPtr& p, bool returnTypeDeclaration)
+{
+ string scoped = p->scoped();
string name = getName(p);
string type = getTypeVar(p);
string abs = getAbsolute(p, _ns);
@@ -205,8 +235,6 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
bool isInterface = p->isInterface();
bool isAbstract = isInterface || p->allOperations().size() > 0; // Don't use isAbstract() - see bug 3739
- startNamespace(p);
-
_out << sp << nl << "global " << type << ';';
if(!p->isLocal() && isAbstract)
{
@@ -358,7 +386,15 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
//
// __toString
//
- _out << sp << nl << "public function __toString()";
+ if (returnTypeDeclaration)
+ {
+ _out << sp << nl << "public function __toString(): string";
+ }
+ else
+ {
+ _out << sp << nl << "public function __toString()";
+ }
+
_out << sb;
_out << nl << "global " << type << ';';
_out << nl << "return IcePHP_stringify($this, " << type << ");";
@@ -703,27 +739,35 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
}
}
}
+}
- endNamespace();
+bool
+CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
+{
+ startNamespace(p);
- if(_classHistory.count(scoped) == 0)
- {
- _classHistory.insert(scoped); // Avoid redundant declarations.
- }
+ _out << sp << nl << "if (PHP_VERSION_ID < 80200)";
+ _out << sb;
+ writeException(p, false);
+ _out << eb;
+ _out << nl << "else";
+ _out << sb;
+ writeException(p, true);
+ _out << eb;
+
+ endNamespace();
return false;
}
-bool
-CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
+void
+CodeVisitor::writeException(const ExceptionPtr &p, bool returnTypeDeclaration)
{
string scoped = p->scoped();
string name = getName(p);
string type = getTypeVar(p);
string abs = getAbsolute(p, _ns);
- startNamespace(p);
-
_out << sp << nl << "global " << type << ';';
_out << nl << "class " << name << " extends ";
ExceptionPtr base = p->base();
@@ -792,7 +836,15 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
//
// __toString
//
- _out << sp << nl << "public function __toString()";
+ if (returnTypeDeclaration)
+ {
+ _out << sp << nl << "public function __toString(): string";
+ }
+ else
+ {
+ _out << sp << nl << "public function __toString()";
+ }
+
_out << sb;
_out << nl << "global " << type << ';';
_out << nl << "return IcePHP_stringifyException($this, " << type << ");";
@@ -865,14 +917,29 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
_out << "null";
}
_out << ");";
+}
+
+bool
+CodeVisitor::visitStructStart(const StructPtr& p)
+{
+ startNamespace(p);
+
+ _out << sp << nl << "if (PHP_VERSION_ID < 80200)";
+ _out << sb;
+ writeStruct(p, false);
+ _out << eb;
+ _out << nl << "else";
+ _out << sb;
+ writeStruct(p, true);
+ _out << eb;
endNamespace();
return false;
}
-bool
-CodeVisitor::visitStructStart(const StructPtr& p)
+void
+CodeVisitor::writeStruct(const StructPtr& p, bool returnTypeDeclaration)
{
string scoped = p->scoped();
string name = getName(p);
@@ -891,8 +958,6 @@ CodeVisitor::visitStructStart(const StructPtr& p)
}
}
- startNamespace(p);
-
_out << sp << nl << "global " << type << ';';
_out << nl << "class " << name;
@@ -910,7 +975,14 @@ CodeVisitor::visitStructStart(const StructPtr& p)
//
// __toString
//
- _out << sp << nl << "public function __toString()";
+ if (returnTypeDeclaration)
+ {
+ _out << sp << nl << "public function __toString(): string";
+ }
+ else
+ {
+ _out << sp << nl << "public function __toString()";
+ }
_out << sb;
_out << nl << "global " << type << ';';
_out << nl << "return IcePHP_stringify($this, " << type << ");";
@@ -962,9 +1034,6 @@ CodeVisitor::visitStructStart(const StructPtr& p)
_out.dec();
}
_out << "));";
- endNamespace();
-
- return false;
}
void
diff --git a/php/src/php/Config.h b/php/src/php/Config.h
index 93226501652..04ca195d2c0 100644
--- a/php/src/php/Config.h
+++ b/php/src/php/Config.h
@@ -34,8 +34,11 @@ extern "C"
#ifdef _WIN32
# pragma warning( disable : 4018) // suppress signed/unsigned mismatch in zend_execute.h (PHP 5.3.x)
#elif defined(__clang__)
+ // Surpress various warnings emitted from including the PHP headers
# pragma clang diagnostic ignored "-Wconversion"
# pragma clang diagnostic ignored "-Wsign-conversion"
+# pragma clang diagnostic ignored "-Wdocumentation"
+# pragma clang diagnostic ignored "-Wshadow"
#elif defined(__GNUC__)
# pragma GCC diagnostic warning "-Wsign-compare"
#endif
@@ -120,6 +123,15 @@ ZEND_END_MODULE_GLOBALS(ice)
ZEND_BEGIN_ARG_INFO(ice_void_arginfo, 0)
ZEND_END_ARG_INFO()
+// An arginfo used for __toString() methods.
+#if PHP_VERSION_ID >= 80200
+ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(ice_to_string_arginfo, IS_STRING, 0)
+ ZEND_END_ARG_INFO()
++#else
+// The return type declaration is optional with PHP < 8.2
+ZEND_BEGIN_ARG_INFO(ice_to_string_arginfo, 0)
+ZEND_END_ARG_INFO()
+#endif
#ifdef ZTS
# define ICE_G(v) TSRMG(ice_globals_id, zend_ice_globals*, v)
#else
diff --git a/php/src/php/Connection.cpp b/php/src/php/Connection.cpp
index ddcb4084694..483a39c95f4 100644
--- a/php/src/php/Connection.cpp
+++ b/php/src/php/Connection.cpp
@@ -478,7 +478,7 @@ static zend_function_entry _interfaceMethods[] =
static zend_function_entry _connectionClassMethods[] =
{
ZEND_ME(Ice_Connection, __construct, ice_void_arginfo, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
- ZEND_ME(Ice_Connection, __toString, ice_void_arginfo, ZEND_ACC_PUBLIC)
+ ZEND_ME(Ice_Connection, __toString, ice_to_string_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, close, Ice_Connection_close_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, getEndpoint, ice_void_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, flushBatchRequests, Ice_Connection_flushBatchRequests_arginfo, ZEND_ACC_PUBLIC)
diff --git a/php/src/php/Endpoint.cpp b/php/src/php/Endpoint.cpp
index 220a5a4b5b8..41e84ec0a79 100644
--- a/php/src/php/Endpoint.cpp
+++ b/php/src/php/Endpoint.cpp
@@ -224,7 +224,7 @@ static zend_function_entry _interfaceMethods[] =
static zend_function_entry _endpointMethods[] =
{
ZEND_ME(Ice_Endpoint, __construct, ice_void_arginfo, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
- ZEND_ME(Ice_Endpoint, __toString, ice_void_arginfo, ZEND_ACC_PUBLIC)
+ ZEND_ME(Ice_Endpoint, __toString, ice_to_string_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Endpoint, toString, ice_void_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Endpoint, getInfo, ice_void_arginfo, ZEND_ACC_PUBLIC)
{0, 0, 0}
diff --git a/php/src/php/Logger.cpp b/php/src/php/Logger.cpp
index 30ca6a66df9..e402602e2bc 100644
--- a/php/src/php/Logger.cpp
+++ b/php/src/php/Logger.cpp
@@ -261,7 +261,7 @@ static zend_function_entry _interfaceMethods[] =
static zend_function_entry _classMethods[] =
{
ZEND_ME(Ice_Logger, __construct, ice_void_arginfo, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
- ZEND_ME(Ice_Logger, __toString, ice_void_arginfo, ZEND_ACC_PUBLIC)
+ ZEND_ME(Ice_Logger, __toString, ice_to_string_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Logger, print, Ice_Logger_print_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Logger, trace, Ice_Logger_trace_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Logger, warning, Ice_Logger_warning_arginfo, ZEND_ACC_PUBLIC)
diff --git a/php/src/php/Properties.cpp b/php/src/php/Properties.cpp
index cc6ba545557..545f7e3bdff 100644
--- a/php/src/php/Properties.cpp
+++ b/php/src/php/Properties.cpp
@@ -657,7 +657,7 @@ static zend_function_entry _interfaceMethods[] =
static zend_function_entry _classMethods[] =
{
ZEND_ME(Ice_Properties, __construct, ice_void_arginfo, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
- ZEND_ME(Ice_Properties, __toString, ice_void_arginfo, ZEND_ACC_PUBLIC)
+ ZEND_ME(Ice_Properties, __toString, ice_to_string_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Properties, getProperty, Ice_Properties_getProperty_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Properties, getPropertyWithDefault, Ice_Properties_getPropertyWithDefault_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Properties, getPropertyAsInt, Ice_Properties_getPropertyAsInt_arginfo, ZEND_ACC_PUBLIC)
diff --git a/php/src/php/Proxy.cpp b/php/src/php/Proxy.cpp
index 36c05e6e7ba..dfd9d2f96fc 100644
--- a/php/src/php/Proxy.cpp
+++ b/php/src/php/Proxy.cpp
@@ -1810,7 +1810,7 @@ handleCompare(zval* zobj1, zval* zobj2)
static zend_function_entry _proxyMethods[] =
{
ZEND_ME(Ice_ObjectPrx, __construct, ice_void_arginfo, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
- ZEND_ME(Ice_ObjectPrx, __toString, ice_void_arginfo, ZEND_ACC_PUBLIC)
+ ZEND_ME(Ice_ObjectPrx, __toString, ice_to_string_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_ObjectPrx, ice_getCommunicator, ice_void_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_ObjectPrx, ice_toString, ice_void_arginfo, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_ObjectPrx, ice_getIdentity, ice_void_arginfo, ZEND_ACC_PUBLIC)
diff --git a/php/test/Ice/checksum/Client.php b/php/test/Ice/checksum/Client.php
index 76199dcef49..a7de8f6099f 100644
--- a/php/test/Ice/checksum/Client.php
+++ b/php/test/Ice/checksum/Client.php
@@ -17,12 +17,10 @@ class Client extends TestHelper
$communicator = $this->initialize($args);
$checksum = allTests($this);
$checksum->shutdown();
- $communicator->destroy();
}
- catch(Exception $ex)
+ finally
{
$communicator->destroy();
- throw $ex;
}
}
}
diff --git a/php/test/TestHelper.php b/php/test/TestHelper.php
index 32e1326048e..cf0a5626178 100644
--- a/php/test/TestHelper.php
+++ b/php/test/TestHelper.php
@@ -17,6 +17,8 @@ require_once('Ice.php');
class TestHelper
{
+ private $_communicator;
+
public function __construct()
{
$this->_communicator = NULL;