diff options
author | Bo Yang <teboring@google.com> | 2017-12-13 17:09:55 -0800 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2017-12-13 17:09:55 -0800 |
commit | 1a549d9a902151e980bfa76093b3d82b7589e158 (patch) | |
tree | 920be65fc7cc81753220f47868be3b5939a5c237 /php/ext/google/protobuf/message.c | |
parent | fffe8d39f810d147c6db65f90ae4f71f4e0f0116 (diff) | |
download | protobuf-1a549d9a902151e980bfa76093b3d82b7589e158.tar.gz protobuf-1a549d9a902151e980bfa76093b3d82b7589e158.tar.bz2 protobuf-1a549d9a902151e980bfa76093b3d82b7589e158.zip |
Avoid using php_date_get_date_ce() in case date extension is not
available.
Diffstat (limited to 'php/ext/google/protobuf/message.c')
-rw-r--r-- | php/ext/google/protobuf/message.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 7d7d8651..df5eb408 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -1123,8 +1123,21 @@ PHP_METHOD(Timestamp, fromDateTime) { zval* datetime; zval member; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &datetime, - php_date_get_date_ce()) == FAILURE) { + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, "z", &datetime) == FAILURE) { + return; + } + + zend_class_entry* ce = Z_OBJCE_P(datetime); + PHP_PROTO_CE_DECLARE datetime_ce; + if (php_proto_zend_lookup_class("\\Datetime", 9, &datetime_ce) == + FAILURE) { + zend_error(E_ERROR, "Make sure date extension is enabled."); + return; + } + + if (!instanceof_function(PHP_PROTO_CE_UNREF(datetime_ce), ce TSRMLS_CC)) { + zend_error(E_USER_ERROR, "Expect Datetime."); return; } |