Camen Design Forum

Uninitialized string offset

append delete toby12

hello I am getting a php error in PHP7 was wondering if anyone could help with this one.

PHP Notice: Uninitialized string offset: 0 in /home/user/tor/public_html/lib/functions.php on line 66

Line 66:

%

foreach ($template->query ('//*/@href, //*/@src, //*/@content') as $node) if ($node->nodeValue[0] == '/')

%

Reply RSS

Replies

append delete #1. Martijn

Oh, interesting!

The code looks for all `href`, `src`, and `content` HTML attributes in the template and then checks their first character. The notice being thrown means there was no first character (ie. it is empty).

Is this on the unchanged template?

Two possible fixes that immediately come to mind:

1. Find where any of those attributes are empty in the template and add some content to them.
2. Expand the `if` on line 66 to make sure the value isn’t empty (something like `strlen($node->nodeValue) > 0` would do the trick) before checking the first character.

append delete #2. toby12

This is the original functions.php the theme is modified. So that I have this right line 66 should look like this?

%

foreach ($template->query ('//*/@href, //*/@src, //*/@content') as $node) if strlen($node->nodeValue) > 0 == '/')

%

I tried that and the site won't load.

append delete #3. Martijn

Was it your modifications to the theme that triggered the error? I’d love to get to the bottom of this.

Sorry, my second possible fix just showed the minimal code that would need to be added, assuming whoever was going to add it knew their way around PHP. The line should probably be something like this (note: not tested):

%
foreach ($template->query ('//*/@href, //*/@src, //*/@content') as $node) if (strlen($node->nodeValue) > 0 && $node->nodeValue[0] == '/')
%

Inside the if statement, it should first check the length of the nodeValue before comparing the first character to `/`.

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn