PHP code notice
PHP code of whmbackup.solutuions gives a php warning (any support channel is apparently dead for now):
PHP Notice: Undefined offset: 1 in /home/myuser/whmbackupsolutions/whmbackup.php on line 49
And:
PHP Notice: Trying to access array offset on value of type null in /home/myuser/whmbackupsolutions/whmbackup.php on line 202
The line 49 says this:
list($arg_x, $arg_y) = explode('=', $arg);
Line 202 says:
if ($save_status["error"] == "1")
The entire code (copy/pasted):
https://wtools.io/paste-code/b6S5
I understand that PHP is getting less and less "liberal" and that the warning might turn into an error only with newer version updates.
The script itself works fine for now.
But if anyone has an easy fix for the problem, I'd appreciate it (I'm not a programmer).
Detailed info about providers whose services I've used:
BikeGremlin web-hosting reviews
Comments
First is because one of the arguments provided is blank, e.g.
param=
. The solution is do not provide empty parameters.Second is because
update_status
function is returning null (or just returning) rather than returning an array, but that function is in an external file.The first is the same as https://stackoverflow.com/questions/16728268/undefined-offset-1
Basically that some of the strings/inputs may not contain a "=" so you should check if the string contains a "=" before doing an explode with it e.g. https://gist.github.com/ialexpw/8b26023071a0e4b8aad35a448ee483ee
Syuh - SFTP Storage Pods from 50GB to TBs. UK, US and DE locations.
most likely comes down to a comparable issue like with the warning seen in wordpress ;-)
coders tend to be lazy and do not properly (pre-)check for cases out of scope, don't initialize vars or simply rely on PHP being forgiving internally and deal with logical errors gracefully. worked for decades...
yes.
Line 202 can be fixed by changing it to the following:
if (is_array($save_status) && $save_status["error"] == "1")
might still throw a warning, if there is no "error" key in that array ;-)
Good point. Ignore my "fix" lol
I did not bother to check if $save_status is not already always an array, but this is sorta bulletproof:
if (is_array($save_status) && array_key_exists("error", $save_status) && $save_status["error"] == "1")
rather not bulletproof, but more likely to still produce the exact same php notice as can be seen initially. if you look at it closely it is complaining about a value of null , so $save_status in this case probably contains something like
'error' => null
...which would still have array_key_exists being true!to fix it properly make sure there is a correct return value for 'error' in any case within the update_status function, so that you ideally can roll with a plain and simple
if($save_status["error"])
in the end.so add before
$save_status["error"] == "1"
a check if the value is null and if it is, change it from null to 0.0 usually means no error.
https://clients.mrvm.net
I believe error is saying that $save_status is null. Accessing array offset "error" is not possible if $save_status is of type null (, which does not implement ArrayAccess). The check I mentioned will first check if the type is an array, then check if the array offset exists (otherwise you will get another notice: "Notice: Undefined offset: error"). The value of $save_status["error"] does not matter. The comparison "==" allows type juggling, so type will not matter for this comparison. It will not complain about the actual value of $save_status["error"] being null.
You're correct - it does prevent the warning. But I think the point is that the function itself should be checked to see why it is returning null and what might have been intended, rather than just come up with a way to suppress the error - should the function just
return array('error' => 1);
instead? And the function itself is in another (not disclosed) file so we can't really reach a conclusion.I had included the entire code in the original post, if that's of any help (I thought it would be important):
https://wtools.io/paste-code/b6S5
This is the entire "package" download link:
https://whmbackup.solutions/download-latest-version/
And this is the, (for) now apparently abandoned, project's home page:
https://whmbackup.solutions/
Detailed info about providers whose services I've used:
BikeGremlin web-hosting reviews
Yea, that function does not return anything. I guess this code could use some "Exception"-love actually. Possibly adding
return array("error" => "0")
at the end of this function might also solve all issues.I see and stand corrected. I only remembered about some difference with array_key_exists and isset for key values of null and therefore probably misinterpreted the error message. looking at the update_status function - your are right, $save_status is of type null
One of the reasons people hate PHP. Not only it allows you to write bad code but pretty much encouraged it for way too long.