Jump to content

error when uprading to PHP 7+


seany1234

Recommended Posts

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 by seany1234
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 by seany1234
Link to comment
Share on other sites

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.

  • Great Answer 1
Link to comment
Share on other sites

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?   

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.