Browse Source

Fix the method_exists "Uncaught Type Error" problem in PHP8

PHP8SoAppetizing 4 năm trước cách đây
mục cha
commit
8b9e917009
3 tập tin đã thay đổi với 4 bổ sung4 xóa
  1. 1 1
      Connection/AsyncTcpConnection.php
  2. 2 2
      Connection/TcpConnection.php
  3. 1 1
      Worker.php

+ 1 - 1
Connection/AsyncTcpConnection.php

@@ -352,7 +352,7 @@ class AsyncTcpConnection extends TcpConnection
                 }
             }
             // Try to emit protocol::onConnect
-            if (\method_exists($this->protocol, 'onConnect')) {
+            if (\is_callable($this->protocol, 'onConnect')) {
                 try {
                     \call_user_func(array($this->protocol, 'onConnect'), $this);
                 } catch (\Exception $e) {

+ 2 - 2
Connection/TcpConnection.php

@@ -271,7 +271,7 @@ class TcpConnection extends ConnectionInterface
      */
     public function __call($name, array $arguments) {
         // Try to emit custom function within protocol
-        if (\method_exists($this->protocol, $name)) {
+        if (\is_callable($this->protocol, $name)) {
             try {
                 return \call_user_func(array($this->protocol, $name), $this, $arguments);
             } catch (\Exception $e) {
@@ -961,7 +961,7 @@ class TcpConnection extends ConnectionInterface
             }
         }
         // Try to emit protocol::onClose
-        if ($this->protocol && \method_exists($this->protocol, 'onClose')) {
+        if ($this->protocol && \is_callable($this->protocol, 'onClose')) {
             try {
                 \call_user_func(array($this->protocol, 'onClose'), $this);
             } catch (\Exception $e) {

+ 1 - 1
Worker.php

@@ -2527,7 +2527,7 @@ class Worker
                 if ($this->protocol !== null) {
                     /** @var \Workerman\Protocols\ProtocolInterface $parser */
                     $parser      = $this->protocol;
-                    if(\method_exists($parser,'input')){
+                    if(\is_callable($parser,'input')){
                         while($recv_buffer !== ''){
                             $len = $parser::input($recv_buffer, $connection);
                             if($len === 0)