From 5f7334f5f3c5015cdcaf21d456f0829486717b15 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 10 May 2018 10:52:00 -0700 Subject: Avoid direct check of class name (#4601) * Avoid direct check of class name So that subclasses are also ok * Use type hint in function signature. --- php/src/Google/Protobuf/Timestamp.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/php/src/Google/Protobuf/Timestamp.php b/php/src/Google/Protobuf/Timestamp.php index 7da8e956..f2286ab4 100644 --- a/php/src/Google/Protobuf/Timestamp.php +++ b/php/src/Google/Protobuf/Timestamp.php @@ -159,14 +159,10 @@ class Timestamp extends \Google\Protobuf\Internal\Message /** * Converts PHP DateTime to Timestamp. * - * @param DateTime $datetime + * @param \DateTime $datetime */ - public function fromDateTime($datetime) + public function fromDateTime(\DateTime $datetime) { - if (get_class($datetime) !== \DateTime::class) { - trigger_error("Given parameter is not a DateTime.", - E_USER_ERROR); - } $this->seconds = $datetime->format('U'); $this->nanos = 0; } @@ -174,7 +170,7 @@ class Timestamp extends \Google\Protobuf\Internal\Message /** * Converts Timestamp to PHP DateTime. Nano second is ignored. * - * @return DateTime $datetime + * @return \DateTime $datetime */ public function toDateTime() { -- cgit v1.2.3