Author |
Message |
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm
Joined: Aug 13, 2009
Posts: 1123
|
Posted:
Fri May 05, 2023 4:04 am |
|
Hello, running php 7.4 I got these errrors from file mainfileend.php
Notice: Trying to access array offset on value of type null in /www.bestbuildpc.org/modules/Your_Account/includes/mainfileend.php on line 24
Notice: Trying to access array offset on value of type null in /www.bestbuildpc.org/modules/Your_Account/includes/mainfileend.php on line 25
Notice: Trying to access array offset on value of type null in /www.bestbuildpc.org/modules/Your_Account/includes/mainfileend.php on line 29
Code:if (isset($user)) {
$uinfo = getusrinfo($user);
$ulevel = $uinfo['user_level'];
$uactive = $uinfo['user_active'];
if (($ulevel < 1) OR ($uactive < 1)) {
unset($user);
unset($cookie);
$sql = 'DELETE FROM `' . $prefix . '_bbsessions` WHERE `session_user_id`="' . $uinfo['user_id'] . '"';
$db->sql_query($sql);
|
What should be the solution? This is happening when I try to deny a user or remove it. |
|
|
|
|
corpse
Regular
Joined: Oct 15, 2007
Posts: 87
|
Posted:
Fri May 05, 2023 10:09 am |
|
That error is saying that null is being given with for the variable $uinfo, which must mean the function getusrinfo() is returning a null value instead of an array.
This may not be right, but, my guess would be to throw in a check to see if it's not null and is an array.
Let's take the full code:
php Code:if (isset($user)) {
$uinfo = getusrinfo($user);
$ulevel = $uinfo['user_level'];
$uactive = $uinfo['user_active'];
if (($ulevel < 1) OR ($uactive < 1)) {
unset($user);
unset($cookie);
$sql = 'DELETE FROM `' . $prefix . '_bbsessions` WHERE `session_user_id`="' . $uinfo['user_id'] . '"';
$db->sql_query($sql);
}
}
|
By changing that to something like this, should stop that error from happening.
php Code:if (isset($user)) {
$uinfo = getusrinfo($user);
if ($uinfo !== null && is_array($uinfo)) {
$ulevel = $uinfo['user_level'];
$uactive = $uinfo['user_active'];
if (($ulevel < 1) OR ($uactive < 1)) {
unset($user);
unset($cookie);
$sql = 'DELETE FROM `' . $prefix . '_bbsessions` WHERE `session_user_id`="' . $uinfo['user_id'] . '"';
$db->sql_query($sql);
}
}
}
|
I've set up Raven on my local running PHP 7.4.9, and I can't reproduce the error, so I don't know. |
|
|
|
|
hicuxunicorniobestbuildpc
|
Posted:
Fri May 05, 2023 4:18 pm |
|
Thanks a lot. The errors is not coming back anymore. I wonder why u didn't get it on localhost running php 7.4. |
|
|
|
|
lonestar1983
New Member
Joined: Apr 26, 2013
Posts: 1
|
Posted:
Fri May 05, 2023 5:29 pm |
|
You may have error reporting turned off on your localhost. |
|
|
|
|
corpse
|
Posted:
Fri May 05, 2023 8:03 pm |
|
hicuxunicorniobestbuildpc wrote: | Thanks a lot. The errors is not coming back anymore. I wonder why u didn't get it on localhost running php 7.4. |
n/p, glad it helped.
lonestar1983 wrote: | You may have error reporting turned off on your localhost. |
Huh, I just looked and in the php.ini I have it turned on and even in the menu for WAMP. I will have to look into it because it's not writing it to a log file either. |
|
|
|
|
neralex
Site Admin
Joined: Aug 22, 2007
Posts: 1773
|
Posted:
Sat May 06, 2023 5:43 am |
|
Thanks corpse! Just added the fix to the repo. [ Only registered users can see links on this board! Get registered or login! ]
I wouldn't recommend it to disable the error-reporting on a local environment, when it is used for testing. But I guess he meant it in another way like: why you are not using a installation on a local environment. |
_________________ Github: RavenNuke |
|
|
|
corpse
|
Posted:
Mon May 08, 2023 11:58 am |
|
neralex wrote: | Thanks corpse! Just added the fix to the repo. [ Only registered users can see links on this board! Get registered or login! ]
I wouldn't recommend it to disable the error-reporting on a local environment, when it is used for testing. But I guess he meant it in another way like: why you are not using a installation on a local environment. |
As for disabling error-reporting, I am a bit confused. On my local, I still need to figure out what's going on, but as it is now, my local is not doing any error reporting, even though the quick look, it is turned on. I bet it's something in my WAMP settings, I just haven't gotten around to it to get it working. I also need to set it up to do it dump the error into an error.log file. I had done that on my old local that was on my old PC, but I guess I didn't do it on this newer PC yet. |
|
|
|
|
hicuxunicorniobestbuildpc
|
Posted:
Thu May 11, 2023 2:17 am |
|
I've got the same issue with Survey module. file index.php
Warning: Trying to access array offset on value of type null in /modules/Surveys/index.php on line 211
Warning: Trying to access array offset on value of type null in /modules/Surveys/index.php on line 123
and when u vote error will come again.
Warning: Trying to access array offset on value of type null in /modules/Surveys/index.php on line 286
I took a look at the lines and I made the right modification I think. Just let me know
Line 123
Code:$optionCount = $row2['optionCount'];
|
Replace with
Code:$optionCount = isset($row2['optionCount']);
|
Line 211
Code:$optionCount = $row2['optionCount'];
|
Replace with
Code:$optionCount = isset($row2['optionCount']);
|
Line 286
Code:$optionCount = $row2['optionCount'];
|
Replace with
Code:
$optionCount = isset($row2['optionCount']);
|
The error dissppear but I would like to know if it is correct. |
|
|
|
|
neralex
|
Posted:
Thu May 11, 2023 2:13 pm |
|
When the array $row2 isn't exist, then the variable $optionCount has no value - just empty. I guess here it would be better to have "0" in this case.
I would do it in this way for example:
php Code:$optionCount = is_array($row2) && isset($row2['optionCount']) ? $row2['optionCount'] : 0;
|
That means at first it checks if the variable $row2 is an array and if so, then it checks if the array-key 'optionCount' exists in the array $row2 and if so too, then the variable $optionCount gets the value of the array-key $row2['optionCount']. If these conditions are not true, the variable $optionCount get the value 0. So the variable always retains a value. Got it? |
|
|
|
|
hicuxunicorniobestbuildpc
|
Posted:
Fri May 12, 2023 2:31 am |
|
Yes this line was much better. it fixed the error as well. Thanks |
|
|
|
|
|