File tree Expand file tree Collapse file tree
user_guide_src/source/incoming Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ trait RequestTrait
4444 /**
4545 * Gets the user's IP address.
4646 *
47- * @return string IP address if it can be detected, or empty string .
47+ * @return string IP address if it can be detected.
4848 * If the IP address is not a valid IP address,
4949 * then will return '0.0.0.0'.
5050 */
@@ -73,6 +73,11 @@ public function getIPAddress(): string
7373
7474 $ this ->ipAddress = $ this ->getServer ('REMOTE_ADDR ' );
7575
76+ // If this is a CLI request, $this->ipAddress is null.
77+ if ($ this ->ipAddress === null ) {
78+ return $ this ->ipAddress = '0.0.0.0 ' ;
79+ }
80+
7681 if ($ proxyIPs ) {
7782 // @TODO Extract all this IP address logic to another class.
7883 foreach ($ proxyIPs as $ proxyIP => $ header ) {
@@ -151,7 +156,7 @@ public function getIPAddress(): string
151156 return $ this ->ipAddress = '0.0.0.0 ' ;
152157 }
153158
154- return empty ( $ this -> ipAddress ) ? '' : $ this ->ipAddress ;
159+ return $ this ->ipAddress ;
155160 }
156161
157162 /**
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ Class Reference
2222
2323 .. php :method :: getIPAddress()
2424
25- :returns: The user's IP Address, if it can be detected, or null . If the IP address
26- is not a valid IP address, then will return 0.0.0.0
25+ :returns: The user's IP Address, if it can be detected. If the IP address
26+ is not a valid IP address, then will return 0.0.0.0.
2727 :rtype: string
2828
2929 Returns the IP address for the current user. If the IP address is not valid, the method
You can’t perform that action at this time.
0 commit comments