seany1234 Posted August 21, 2019 Share Posted August 21, 2019 (edited) Hi, I'm trying to upgrade a website to PHP 7+, currently its on Version 5.6 The website uses a custom wordpress theme which the developers are no longer reachable. when i do the upgrade, pictures of the website no longer appear and having looked at the source code its showing this error message - Quote Use of undefined constant t - assumed 't' I have been able to narrow the problem code to below: <?php $images = get_group('Banner Images'); ?> <?php foreach ($images as $image) { foreach ($image as $paths) { foreach ($paths as $path) { ?> <img src="<?php echo $path[t];?>"/> any idea what the t is used for in the $path array? all help would be amazing Kind regards Sean Edited August 21, 2019 by seany1234 Quote Link to comment https://forums.phpfreaks.com/topic/309115-error-when-uprading-to-php-7/ Share on other sites More sharing options...
ginerjm Posted August 21, 2019 Share Posted August 21, 2019 Obviously the 't' is meant as an index into the array that is in $path. One should ALWAYS use quotes around an index value unless it is a php variable name. Since you are using something called just "t" you need to figure out what belongs there - most likely a dollar sign. Clearing that up and avoiding what php is defaulting your index to (from the error message it may be simply the value "t") an incorrect value. Do you know what $path actually contains? You can do a bit of debugging by simply displaying it. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309115-error-when-uprading-to-php-7/#findComment-1569108 Share on other sites More sharing options...
Barand Posted August 21, 2019 Share Posted August 21, 2019 The error is nothing to do with the upgrade, except that error reporting got turned on. When PHP comes across an unquoted string then it assumes it is a defined constant. It then searches for the definition. Not finding a definition it then assumes it is string literal ("t"). This is only a warning and doesn't affect the running of the code (other than slowing it down while it searches for a constant definition). The question is, therefore, "Is there a key "t" in the $path array?" Try adding a line of code to debug... <?php $images = get_group('Banner Images'); ?> <?php echo '<pre>.print_r($images, true).'</pre>'; // ADD THIS LINE foreach ($images as $image) { . . . Post the output from that line so we can see the data. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309115-error-when-uprading-to-php-7/#findComment-1569109 Share on other sites More sharing options...
seany1234 Posted August 21, 2019 Author Share Posted August 21, 2019 (edited) thanks for your replies echo path just returns 'Array', but i have followed Barands advice and the array is showing as below... Array ( [1] => Array ( [images] => Array ( [1] => Array ( [t] => http://astraframe.co.uk/wp-content/files_mf/cache/th_f2defad1772165b732faf2d184e379d3_windowtradecentrenorwich.jpg [o] => http://astraframe.co.uk/wp-content/files_mf/windowtradecentrenorwich.jpg [src] => http://astraframe.co.uk/wp-content/files_mf/windowtradecentrenorwich.jpg [name] => windowtradecentrenorwich.jpg ) [2] => Array ( [t] => http://astraframe.co.uk/wp-content/files_mf/cache/th_f2defad1772165b732faf2d184e379d3_buywindowsdirectfromastraframe17.png [o] => http://astraframe.co.uk/wp-content/files_mf/buywindowsdirectfromastraframe17.png [src] => http://astraframe.co.uk/wp-content/files_mf/buywindowsdirectfromastraframe17.png [name] => buywindowsdirectfromastraframe17.png ) [3] => Array ( [t] => http://astraframe.co.uk/wp-content/files_mf/cache/th_f2defad1772165b732faf2d184e379d3_conservatoriesinnorwichcopy.png [o] => http://astraframe.co.uk/wp-content/files_mf/conservatoriesinnorwichcopy.png [src] => http://astraframe.co.uk/wp-content/files_mf/conservatoriesinnorwichcopy.png [name] => conservatoriesinnorwichcopy.png ) [4] => Array ( [t] => http://astraframe.co.uk/wp-content/files_mf/cache/th_f2defad1772165b732faf2d184e379d3_astraframeconservatoriesfrom2995copy.png [o] => http://astraframe.co.uk/wp-content/files_mf/astraframeconservatoriesfrom2995copy.png [src] => http://astraframe.co.uk/wp-content/files_mf/astraframeconservatoriesfrom2995copy.png [name] => astraframeconservatoriesfrom2995copy.png ) ) ) ) Edited August 21, 2019 by seany1234 Quote Link to comment https://forums.phpfreaks.com/topic/309115-error-when-uprading-to-php-7/#findComment-1569110 Share on other sites More sharing options...
Barand Posted August 21, 2019 Share Posted August 21, 2019 Looks like it's just the quotes that are missing IE use <img src="<?php echo $path['t'];?>"/> But as that is what the code is doing for you anyway it isn't going to cure the problem of images not appearing. You could try <img src="<?php echo $path['o'];?>"/> or <img src="<?php echo $path['src'];?>"/> If none of those work then the images ain't there anymore. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309115-error-when-uprading-to-php-7/#findComment-1569113 Share on other sites More sharing options...
seany1234 Posted August 21, 2019 Author Share Posted August 21, 2019 both 't' and 'src' are working now after i upgraded to PHP 7+ thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/309115-error-when-uprading-to-php-7/#findComment-1569116 Share on other sites More sharing options...
ginerjm Posted August 22, 2019 Share Posted August 22, 2019 I am curious as to what exactly "fixed" your issue. Hopefully you learned that you should wrap those "t" and "scr" indices with quotes and not left them stranded with no definition, causing php to have to work to understand what you are doing. True? Quote Link to comment https://forums.phpfreaks.com/topic/309115-error-when-uprading-to-php-7/#findComment-1569127 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.