is_a is deprecated, instanceof only takes vars or constants
Summary: Solution, dummy static class var to use instanceof
Reviewed By: dweatherford
Test Plan: Regen'd some mobile code in trunk using this
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665401 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index eeac91e..5b3c979 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -1336,7 +1336,7 @@
generate_deserialize_container(out, type, name);
} else if (type->is_base_type() || type->is_enum()) {
- out << indent() << "if (is_a($input,'TBinaryProtocolAccelerated') && function_exists('thrift_protocol_binary_deserialize')) {" << endl;
+ out << indent() << "if (($input instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_binary_deserialize')) {" << endl;
indent_up();
string ttype_name;
if (type->is_enum()) {
@@ -1496,7 +1496,7 @@
void t_php_generator::generate_deserialize_container(ofstream &out,
t_type* ttype,
string prefix) {
- out << indent() << "if (is_a($input, 'TBinaryProtocolAccelerated') && function_exists('thrift_protocol_binary_deserialize'))" << endl;
+ out << indent() << "if (($input instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_binary_deserialize'))" << endl;
scope_up(out);
string ttype_name;
diff --git a/lib/php/src/protocol/TProtocol.php b/lib/php/src/protocol/TProtocol.php
index 658e54c..7e736d5 100644
--- a/lib/php/src/protocol/TProtocol.php
+++ b/lib/php/src/protocol/TProtocol.php
@@ -39,6 +39,12 @@
* Protocol base class module.
*/
abstract class TProtocol {
+ // The below may seem silly, but it is to get around the problem that the
+ // "instanceof" operator can only take in a T_VARIABLE and not a T_STRING
+ // or T_CONSTANT_ENCAPSED_STRING. Using "is_a()" instead of "instanceof" is
+ // a workaround but is deprecated in PHP5. This is used in the generated
+ // deserialization code.
+ static $TBINARYPROTOCOLACCELERATED = 'TBinaryProtocolAccelerated';
/**
* Underlying transport
@@ -63,7 +69,7 @@
return $this->trans_;
}
- /**
+ /**
* Writes the message header
*
* @param string $name Function name
@@ -112,19 +118,19 @@
public abstract function writeMapBegin($keyType, $valType, $size);
public abstract function writeMapEnd();
-
+
public abstract function writeListBegin($elemType, $size);
-
+
public abstract function writeListEnd();
public abstract function writeSetBegin($elemType, $size);
public abstract function writeSetEnd();
-
+
public abstract function writeBool($bool);
public abstract function writeByte($byte);
-
+
public abstract function writeI16($i16);
public abstract function writeI32($i32);
@@ -150,7 +156,7 @@
public abstract function readMessageEnd();
public abstract function readStructBegin(&$name);
-
+
public abstract function readStructEnd();
public abstract function readFieldBegin(&$name, &$fieldType, &$fieldId);
@@ -162,17 +168,17 @@
public abstract function readMapEnd();
public abstract function readListBegin(&$elemType, &$size);
-
+
public abstract function readListEnd();
public abstract function readSetBegin(&$elemType, &$size);
-
+
public abstract function readSetEnd();
public abstract function readBool(&$bool);
-
+
public abstract function readByte(&$byte);
-
+
public abstract function readI16(&$i16);
public abstract function readI32(&$i32);
@@ -343,7 +349,7 @@
}
default:
return 0;
- }
+ }
}
}
@@ -358,6 +364,6 @@
*/
public function getProtocol($trans);
}
-
+
?>