News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Keep getting this error "8: Trying to access array offset on value of type null"

Started by Wellwisher, December 25, 2021, 03:23:04 PM

Previous topic - Next topic

Wellwisher

Hi,

I keep getting this error "8: Trying to access array offset on value of type null"

Error shows as follows:
"URL: https://www.mysite.com/forum/index.php?action=search2
8: Trying to access array offset on value of type null
File: /home/home/site.com/forum/Themes/main-theme/Search.template.php
Line: 300"


This being the 300th line being:


<div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">


The forum still works and the search works as normal but it's bugging me seeing it listed so often as an error. The error is only generated when a member puts in a search bar query.

Any help would be much appreciated.

I have a custom theme hence I thought I'd post it in the coding section.  :P

shawnb61

A question worth asking is born in experience & driven by necessity. - Fripp

Wellwisher

Quote from: shawnb61 on December 25, 2021, 04:39:53 PMPhp version?

Smf version?

This is usually a sign of running php 8 where it's not supported:
https://wiki.simplemachines.org/smf/SMF2.0:Main_Page

@shawnb61 PHP 7.4 CGI W/ Version SMF 2.0.19
I have PHP OpCache on - not sure if that makes a difference

As I said, it's not urgent but seeing it come up so often makes me want to kick an orphan in the nuts.

shawnb61

A question worth asking is born in experience & driven by necessity. - Fripp

Wellwisher

Quote from: shawnb61 on December 25, 2021, 04:59:42 PMMods?


Mods:

1.   Add Social Media Icons To Profiles   1.1.0    
2.   Bookmarks   2.5    
3.   SMF Likes Plus   1.5
4.   Default Avatar   2.3
5.   Ad Managment   3.2    
6.   GoogAd Mod v.1.4   1.3
7.   @mention members   1.1.2    
8.   TopicRenamer   2.2    
09.   Tagging System   3.0
10.   SimplePortal   2.3.7    
11.   Auto [iurl] For Internal Links And "nofollow" For External Links   1.0    
12.   Yet Another Spoiler Mod   1.1
13.   Simple Audio Video Embedder   6.0.3    

SMF UPDATES:

1.   SMF 1.1.19 / 2.0.6 Update   1.0
2.   SMF 1.1.20 / 2.0.9 Update   1.0    
3.   SMF 2.0.5 Update   1.0
4.   SMF 2.0.7 Update   1.0    
5.   SMF 2.0.8 Update   1.0
6.   SMF 1.1.21 / 2.0.10 Update   1.0
7.   SMF 2.0.11 Update   1.0
8.   SMF 2.0.12 Update   1.0    
9.   SMF 2.0.13 Update   1.0    
10.   SMF 2.0.14 Update   1.0    
11.   SMF 2.0.15 Update   1.0    
12.   SMF 2.0.16 Update   1.0    
13.   SMF 2.0.17 Update   1.0    
14.   SMF 2.0.18 Update   0.1.0    
15.   SMF 2.0.19 Update   1.0    

shawnb61

A question worth asking is born in experience & driven by necessity. - Fripp

Wellwisher

Quote from: shawnb61 on December 25, 2021, 06:13:25 PMAuto iurl?

Not familiar with that mod...

It's a clever little mod. I managed to track down an old SMF mod author (who I think has left SMF forum) but he's got his mods on Github.  It differentiates the internal links from external links. Automatically adds "iurl" tag for internal links, so that they are opened in the same window and adds "nofollow" to all external links.

Great for SEO

https://github.com/LinuxPanda/SMF2.0Mod--Auto_-iurl-_For_Internal_Links_And_-nofollow-_For_External_Links

Chen Zhen

0 or null will be empty, so try:

<div class="', empty($message['alternate']) ? 'windowbg' : 'windowbg2', ' core_posts">

My SMF Mods & Plug-Ins

WebDev

SMF support staff should be shaping a positive community experience & not provoking an argument or emotional reaction.

Wellwisher

Quote from: Chen Zhen on December 25, 2021, 09:56:14 PM<div class="', empty($message['alternate']) ? 'windowbg' : 'windowbg2', ' core_posts">

@Chen Zhen Thank you, that worked like a charm!!!  :laugh:  :laugh:  :laugh:  No more errors. That's 2 for 2 helping me out. Thank you again matey!  ;D

Marking as solved <3

shawnb61

FYI - Chen Zhen's recommended code matches 2.0.19 for that line.  So somehow, some updates weren't applied.
A question worth asking is born in experience & driven by necessity. - Fripp

Wellwisher

Quote from: shawnb61 on December 25, 2021, 11:08:02 PMFYI - Chen Zhen's recommended code matches 2.0.19 for that line.  So somehow, some updates weren't applied.

It could be because I have a custom theme? I simply copied over some files from the "Default SMF" theme into my "custom theme" to modify them.

What's strange is when I was installing 2.0.19, it did not show me a 'warning' that I had to change this code in my custom theme. I mean, there was one change that I had to make, which I did, but the rest was fine ??? See attached.

Chen Zhen

Patch/Upgrade file dates: 12/22

The upgrade package provides a replacement file solely for the default theme.
However, for the patch this edit was not included in the xml parse file.

My SMF Mods & Plug-Ins

WebDev

SMF support staff should be shaping a positive community experience & not provoking an argument or emotional reaction.

shawnb61

Quote from: Chen Zhen on December 26, 2021, 12:07:36 PMPatch/Upgrade file dates: 12/22

The upgrade package provides a replacement file solely for the default theme.
However, for the patch this edit was not included in the xml parse file.


That edit was made in 2.0.18, so you wouldn't see it in the .19 patch. 

I suspect the 'copying files over' is at root here.  Depends which files, when, etc. 

A question worth asking is born in experience & driven by necessity. - Fripp

Chen Zhen


Any custom theme or mod for that matter will have to depend on its author or the site admin to fix/update anything like that.

IMO checking if a variable (or array key value) isn't null prior to attempting to use it should have been in practice prior to PHP 8. Although I suppose it's difficult to catch everything when/if an error wasn't flagged in previous PHP versions.

My SMF Mods & Plug-Ins

WebDev

SMF support staff should be shaping a positive community experience & not provoking an argument or emotional reaction.

shawnb61

Just an FYI - When applying patches, the package manager will attempt to propagate changes made to the default theme across any themes installed.  Of course, a lot depends on how old the theme files are, how much of the code was tweaked, etc.

Yes, php has morphed from an extremely friendly & forgiving scripting language to something closer to a real language.  I expect to see strong type checking in the future...
A question worth asking is born in experience & driven by necessity. - Fripp

live627

That future is known as PHP 7. PHP 8 made that future stronger.

petewadey

Quote from: Chen Zhen on December 25, 2021, 09:56:14 PM0 or null will be empty, so try:

<div class="', empty($message['alternate']) ? 'windowbg' : 'windowbg2', ' core_posts">

I'm getting the same error message for these 2 lines in Sources/Gallery2.php Any ideas what I should try instead?

'password' => $row4['password'],

'private' => $row4['private'],

SMF 2.0.19 php 7.4

Thanks


Advertisement: