Bug #80803 [Opn->Fbk]: socket_read() reference to global socket fails in user function
| From: | requinix@php.net | Date: | Fri, 26 Feb 2021 15:39:36 +0000 |
| Subject: | Bug #80803 [Opn->Fbk]: socket_read() reference to global socket fails in user function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232399@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80803&edit=1
ID: 80803
Updated by: requinix@php.net
Reported by: janui at onmat dot com
Summary: socket_read() reference to global socket fails in
user function
-Status: Open
+Status: Feedback
Type: Bug
Package: *Data Exchange functions
Operating System: Linux 5.10.14-2-ARCH armv7l
PHP Version: 8.0.2
Block user comment: N
Private report: N
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
Previous Comments:
------------------------------------------------------------------------
[2021-02-26 11:02:37] janui at onmat dot com
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 this bug report at https://bugs.php.net/bug.php?id=80803&edit=1