Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying Categories

I'm getting the "Warning: Illegal string offset 'category' in home/treehouse/workspace/inc/functions.php on line 19" err

I'm getting the "Warning: Illegal string offset 'category' in home/treehouse/workspace/inc/functions.php on line 19" error when I click on the different category pages. What is the problem?

1 Answer

Hi Robert,

In this earlier video at around 0:48, https://teamtreehouse.com/library/build-a-basic-php-website/listing-and-sorting-inventory-items/associative-arrays

the $catalog array was cut from catalog.php and moved to data.php where it was changed from a simple array of strings to a multi-dimensional array.

Did you leave the old catalog array in catalog.php? If your code is still using that array then it would produce the type of warning you're getting.

That warning happens whenever you try to access a character of a string using a string index instead of an integer index.

I've included a code sample below that illustrates how this warning happens.

<?php

$name = "Mike";
echo $name[0]; // outputs M
echo $name["first"]; // issues WARNING Illegal string offset 'first' on line number 5

If this doesn't resolve your issue, you can post a snapshot of your workspace and someone can take a look.