PHP notices: "Undefined offset" and "Trying to get property of non-object"

Hi,

I am working on a staging site. I am on debug mode (‘WP_DEBUG’, true ). I get all the notices on the front end of the site, even with all the plugins deactivated. My PHP version is 7.0.23.

Transcription:

Notice: Undefined offset: 0 in …/xxx/wp-content/themes/pro/framework/functions/global/portfolio.php on line 55

Notice: Trying to get property of non-object in …/xxx/wp-content/themes/pro/framework/functions/global/portfolio.php on line 55

NOTICE: UNDEFINED OFFSET: 0 IN …/xxx/WP-CONTENT/THEMES/PRO/FRAMEWORK/FUNCTIONS/GLOBAL/PORTFOLIO.PHP ON LINE 37

NOTICE: TRYING TO GET PROPERTY OF NON-OBJECT IN …/xxx/WP-CONTENT/THEMES/PRO/FRAMEWORK/FUNCTIONS/GLOBAL/PORTFOLIO.PHP ON LINE 37

Thanks!

Hi There,

Could you please try editing your portfolio settings(change the columns, filter, …) then save that page again?

Let us know how it goes!

Hi There,

I am not quite sure what you mean by “portfolio settings” or “filter” but I have:

  • Edited some portfolio items, rearranging the metaboxes, switching on/off some of them and then updating them.
  • Changed some of the options in Theme Options >>Portfolio then saving them.

The PHP notices still persist.

Thanks!

Hey There,

Have you tried setting the portfolio page settings yet? Would you mind providing us with login credentials so we can check your settings. Please provide following information:

Set it as Secure Note

  • Link to your site
  • WordPress Admin username / password
  • FTP credentials

Hi there,

I have enclosed the requested info above your previous reply ( I could not find a way to reply below it with a secure note).

Thanks!

Hi there,

It should be okay now, cheers!

Hi @Rad,

Please, may i know what you did to solve the issue? You have fixed the staging site but I would like to solve (myself) the issue on the production site. I suppose you have not set WP_DEBUG or WP_DEBUG_DISPLAY to false, have you?

Thanks!

Hello There,

Thanks for updating in! The PHP notices were displaying the messages that tells that the variables were undefined. This is because most of the variables were not set or initialized. Nothing to worry about these message as these does not halt any features. It will just be annoying seeing the messages when debug mode is turn on. To get rid of it, you can simply disable the debug mode and debug mode display.

Hope this helps.

@thai, @Jade, @Rad and @RueNel in my very first message the first thing I pointed out was:

“I am working on a staging site. I am on debug mode (‘WP_DEBUG’, true )”

It is obvious I was aware of what implies having debug mode enabled, so getting rid of the PHP notices –per se– was not my objective, even more taking into account that I clarified that this is a staging site.

When building a new website or working on a staging/testing site it is very common to have debug mode enabled to detect possible incompatibilities with new plugins and other potential issues. If the PRO theme causes that “most of the variables are not set or initialised” for the portfolio item pages and because of that those pages get filled with notices then it gets harder for the person building the site to detect new possible warnings and of course it is very annoying.

Having said that, I believe Themeco support team should find a solution to get rid of those PHP notices without having to disable debug mode. No theme should fill its customers screens with PHP notices because they are working on debug mode.

On the other hand –even if you disagree with my previous words– I would like to point out that it has taken 4 members of Themeco support team, 8 messages and a request for login credentials to do something that could had been solved by 1 member on 1 message by simply saying “we do not care about PHP notices, just switch debug mode off, we are not going to provide you with a solution”, at least we hadn’t wasted our time, all of us.

Hello Again,

We apologize that this thread has taken 4 members of Themeco support team, 8 messages and a request for login credentials to properly resolve your issue.

As I have explain before, this notices will appear since the variables on the page is not yet set or initialize. This will always happen especially if you haven’t finish developing the site. If turning off the debug mode is not an option, then we will have to continue and finish your site. Please enabled the debug mode again. Do not worry about the notices because it will be gone if you follow the last few steps. And that would be to do the following:
1.) Please create a new page.
2.) You can give it a page title like for example “Portfolio”
3.) While you are in the page editing screen, find the “Page Attributes” meta box.
4.) Please select “Layout - Portfolio” as your page template.
5.) Hit save or update button

To check whether the PHP notices is gone, please click any of your portfolio item page. You should no longer be seeing those notices.

Please let us know how it goes. Thank you very much for your understanding.

Hello @RueNel,

Your last message is the right answer to my initial support request, thanks!. This is what I meant when I said that with only 1 message the topic could have been solved, instead of 9…and no need for credentials.

If a support staff member is not able to provide a relevant, thoughtful and consisten answer to a support request placed by a user then it is better not to post anything as it will cause confusion, will waist user’s time and pollute the thread (other support staff members will have to read it and will provably be misled).

Nevertheless, although I understand that normally when someone adds portfolio items (single) is because there is going to be a portfolio page gathering all of them as a list, that is not always the case. I suggest Themeco’s developers to add some code to make sure all the variables are yet set or initialised even if it does not exist (and perhaps never will) a portfolio page (using “Layout - Portfolio”, i.e., a list of the portfolio items).

In my case I use the portfolio items to feed a “The Grid” grid, which is being used with the same purpose of a portfolio page (a list of portfolio items). I think many other users may take a similar approach so that is why I make this code improvement request, which I believe is very reasonable.

Thanks!

Thank you for your valuable feedback,

I will forward it to our developers.