Bug #80803 [NEW]: socket_read() reference to global socket fails in user function
| From: | janui at onmat dot com | Date: | Fri, 26 Feb 2021 11:02:37 +0000 |
| Subject: | Bug #80803 [NEW]: socket_read() reference to global socket fails in user function | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-232392@lists.php.net to get a copy of this message | ||
From: janui at onmat dot com
Operating system: Linux 5.10.14-2-ARCH armv7l
PHP version: 8.0.2
Package: *Data Exchange functions
Bug Type: Bug
Bug description:socket_read() reference to global socket fails in user function
Description:
------------
---
From manual page: https://php.net/function.socket-read
---
When a user function contains a socket_read() which references a
globally defined socket object it fails to connect to and read the
socket. When the same code used in the top-level script it works
correctly. The problem is not present in the socket_connect(),
socket_write() and socket_close() functions.
function user_function_read_socket($socketVariableName)
{
$buff = 4096;
global $$socketVariableName;
echo $socketVariableName."\n";
var_dump($$socketVariableName);
$response = socket_read($$socketVariableName, $buff, PHP_NORMAL_READ);
echo $response."\n";
echo socket_strerror(socket_last_error($$socketVariableName))."\n";
}
The following similar construction has no effect on the result:
$response = socket_read($GLOBALS[$socketVariableName], $buff,
PHP_NORMAL_READ);
Test script:
---------------
See description. A full test script can be delivered., something like
this:
<?php
function user_function_open_socket($socketVariableName)
{...}
function user_function_write_socket($socketVariableName, $command)
{...}
function user_function_read_socket($socketVariableName)
{...see description...}
function user_function_close_socket($socketVariableName)
{...}
$socketVariableName = 'testSocketName';
$command = 'a valid command';
user_function_open_socket($socketVariableName);
user_function_write_socket($socketVariableName, $command);
user_function_read_socket($socketVariableName);
// paste the code from the read function here
user_function_close_socket($socketVariableName);
Expected result:
----------------
I would expect the code to work in the same way regardless of being used
in the top level script as in a user function.
--
Edit bug report at https://bugs.php.net/bug.php?id=80803&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80803&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80803&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80803&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80803&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80803&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80803&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80803&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80803&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80803&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80803&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80803&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80803&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80803&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80803&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80803&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80803&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80803&r=mysqlcfg