Uninitialized string offset

I’m new to this group so I’m not sure if I’m posting this in the right category but I’m having a problem with some error messages that appear in Chrome’s View Page Source. They are generated after running a script that displays correctly on a web page but not in View Page Source. They seem to be connected to an array that I’m using in one of the classes. Without getting into too much detail, gettype() calls the array ‘array’ on the page but in View Page Source it calls it ‘string’. Because of this it generates a number of ‘Notice: Uninitialized string offset’ messages in code that follows that statement. This occurs when xdebug is enabled or disabled. If I hard-code this array in a separate script, independent of the program I’ve written, and run a loop to display data I get no errors in View Page Source as it only occurs within the program.

If anyone has some good advice as to why this is happening I’d appreciate it. Thanks.

can you post some code? its hard to tell from description and probably something easy to spot in code

Its part of a method within a class that’s over 6000 lines but this is the part that causes the error…

// Retrieve the MySql array
$reportArr = $this->findArrValue(‘logArr’);
echo 'type: '.gettype($reportArr);

Its calling a method that looks up a value in another array. The value is the array I need. It finds it and returns it. Then like I said it displays it and everything’s fine on-screen. It’s just the HTML source code that shows it as a string and not an array.

whats the contents of $this->findArrValue(‘logArr’); function? also how do you pass it to view

Its an array that displays one of the tables on the page, then its processed and its data is returned as part of an HTML string and echoed to the screen.

this is how it should look like:

in controller

$reportArr = ['bla bla'];
$this->set('array', $reportArr);

in view

echo 'type: ' . gettype($array);

do you have something similar? im asking because i would really prefer to see code instead of description that may or may not be doing what you are saying :slight_smile:

I don’t have exactly what you describe as $reportArr is a local var within the method that calls findArrValue() which returns the array I need. I employ findArrValue() because that method searches a multidimensional array ($data) for a value. In this case its ‘logArr’. When it finds that it extracts the next value in the subarray which happens to be $logArr ($reportArr). $data contains subarrays that have both arrays and strings as values and is ‘set’ as a private class var and can be accessed many times using findArrValue(). If I call gettype() from within findArrValue() I get the same result as when its called from the method that generates the uninitialized string offset errors I’m getting. gettype() returns it as an array in both locations in the code. I don’t understand why it echoes ‘array’ on the screen and ‘string’ in View Page Source. Its like something is overriding the code and changing its properties, but what? Its not xdebug as with or without it enabled, the same result occurs. It’s probably something simple that’s causing it but I’ve not encountered this before and its a real mystery to me. I will gladly provide you with code but I don’t know where to start looking for the code you may need to analyze. Based on my description, maybe you could suggest a starting point. By the time findArrValue() is called and returns $reportArr, debug_backtrace() will probably show at least 8 calls between the controller script and addDetail(), the method that contains $reportArr. I’m sorry if this is confusing but it is a rather large program. Thank you for your assistance.

is when you have string and trying to access its element that doesnt exist ie

$a = 'bla';
$a[0]; // ok
$a[5]; // notice

why its happening in your code? i dont know you dont want to post any code ive asked you to.

Well I’ve narrowed the problem down to the Chrome browser. I get no errors in IE or Firefox. It appears that when data is sent to another page via _POST (as in a form), the HTML/data that is displayed in the forwarded pages’ View Page Source does not reflect the same data that appears on the current page so as I see it, any errors that are displayed should be ignored. As a result I intend to use Firefox instead of Chrome for development. I can’t find any recent posts about any fixes Google may have implemented regarding this issue so I’m assuming it’s still not fixed. Perhaps they don’t consider it important? Thank you all for trying to help me out with this. I think I can rest assured that it’s not a coding issue.