No Code Attached Yet bug
avatar brianteeman
brianteeman
23 Sep 2023

In php 8  track_errors which caused $php_errormsg to be available has been removed.

This is used extensively in 5 of the cms libraries.

Presumably this means that the error handling and reporting is not taking place in these situations.

Sorry no PR from me on this as I see different solutions in drupal, moodle etc to address this and I am unsure how to test

Examples

// Capture hidden PHP errors from the parsing.
if ($debug === true) {
// See https://www.php.net/manual/en/reserved.variables.phperrormsg.php
$php_errormsg = null;
$trackErrors = ini_get('track_errors');
ini_set('track_errors', true);
}

// Capture PHP errors
$php_errormsg = '';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// PHP sends a warning if the uri does not exists; we silence it and throw an exception instead.
// Attempt to connect to the server
$connection = @fsockopen($host, $port, $errno, $err, $timeout);
if (!$connection) {
if (!$php_errormsg) {
// Error but nothing from php? Create our own
$php_errormsg = sprintf('Could not connect to resource %s: %s (error code %d)', $uri, $err, $errno);
}
// Restore error tracking to give control to the exception handler
ini_set('track_errors', $track_errors);
throw new \RuntimeException($php_errormsg);
}
// Restore error tracking to what it was before.
ini_set('track_errors', $track_errors);
// Since the connection was successful let's store it in case we need to use it later.
$this->connections[$key] = $connection;
// If an explicit timeout is set, set it.
if (isset($timeout)) {
stream_set_timeout($this->connections[$key], (int) $timeout);
}
return $this->connections[$key];
}

avatar brianteeman brianteeman - open - 23 Sep 2023
avatar joomla-cms-bot joomla-cms-bot - change - 23 Sep 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 23 Sep 2023
avatar HLeithner
HLeithner - comment - 23 Sep 2023

All of this has to be change to the current code but I think it's not a blocker. It's only produces deprecation messages? and of course no error detection.

avatar brianteeman
brianteeman - comment - 23 Sep 2023

All of this has to be change to the current code but I think it's not a blocker. It's only produces deprecation messages? and of course no error detection.

No, it produces no messages at all and no error detection which in my book maks it a blocker

avatar Fedik
Fedik - comment - 23 Sep 2023

When need, we can capture the errors with set_error_handler https://www.php.net/manual/en/function.set-error-handler.php

But I do not see where that capture actualy happen in LanguageHelper::parseIniFile.
To me it doing nothing, just reset $php_errormsg which is deprecated also.

I suspect, no one will notice when we remove that :)

In SocketTransport it just do something like echo errormsg, wich can be done with trigger_error https://www.php.net/manual/en/function.trigger-error.
Idealy it should be an exception, but need to look how whole SocketTransport works.

Ah there already an exception

throw new \RuntimeException($php_errormsg);

So it also can be removed.

Not a blocker.

avatar rdeutz
rdeutz - comment - 23 Sep 2023

As far as I see it, then we do all the track_error handeling because we want to catch the error message in $php_errormsg. But $php_errormsg is deprecated with 7.2.0 and "Relying on this feature is highly discouraged". " track_errors" has been removed with 8.0. I would remove all this entirely.

avatar Denitz
Denitz - comment - 23 Sep 2023

Regarding LanguageHelper and parse_ini_file:

We can suppress the E_WARNING and use recommended error_get_last():

@parse_ini_string('ERROR_CODE=1"');
var_dump(error_get_last());

Regarding SocketTransport and fsockopen:

We can suppress the E_WARNING and rely on $error_message or error_get_last() as well, test this:

@fsockopen('invalid-domain', 80, $error_code, $error_message);
var_dump($error_message);
var_dump(error_get_last());

Can create PR if required.

avatar richard67 richard67 - change - 23 Sep 2023
Labels Added: bug
avatar richard67 richard67 - labeled - 23 Sep 2023
avatar HLeithner
HLeithner - comment - 23 Sep 2023

we should never (if possible) use @ to suppress warnings. If you can create a PR which replace all this $php_errormsg with the correct new code it would be really help full (throwing exception would make sense), btw. we already have an issue or pr where we talked about this. I think it's part of the File and Folder refactoring done by @Hackwar but can't remember the number

avatar brianteeman
brianteeman - comment - 23 Sep 2023

Found these issues and pull requests #25789 #17856 #33185

avatar Denitz
Denitz - comment - 24 Sep 2023

@HLeithner Please advise should it be a 5.0-dev PR? or 4.3-dev PR?

avatar Denitz
Denitz - comment - 24 Sep 2023

@ suppressing can be avoided via set_error_handler(), example:

set_error_handler(static function($errno, $errstr) {
    throw new Exception($errstr);
}, \E_WARNING);

try {
    fsockopen('invalid-domain', 80);
} catch(Exception $e) {
    var_dump($e->getMessage());
} finally {
    restore_error_handler();
}
avatar HLeithner
HLeithner - comment - 24 Sep 2023

Joomla 5.0 is fine, we can back port when 4.4 RMs have time for it.

avatar Denitz
Denitz - comment - 24 Sep 2023
avatar richard67 richard67 - close - 24 Sep 2023
avatar richard67
richard67 - comment - 24 Sep 2023

Closing as having a pull request. Please test #41908 . Thanks in advance.

avatar richard67 richard67 - change - 24 Sep 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-09-24 19:46:58
Closed_By richard67

Add a Comment

Login with GitHub to post a comment