Advertisement:

Author Topic: SOLVED I'm getting php notices in my log files  (Read 2893 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
SOLVED I'm getting php notices in my log files
« on: July 22, 2017, 10:30:58 am »
PHP Notice:  Undefined index: fk_i_category_id in /oc-includes/osclass/helpers/hDefines.php on line 487
PHP Notice:  Undefined index: pk_i_id in /oc-includes/osclass/helpers/hDefines.php on line 493
PHP Notice:  Undefined index: s_city in /oc-includes/osclass/helpers/hDefines.php on line 494
PHP Notice:  Undefined index: s_title in /oc-includes/osclass/helpers/hDefines.php on line 495

How to define them?

Code: [Select]
    /**
     * Create item url from item data without exported to view.
     *
     * @since 3.3
     * @param array $item
     * @param string $locale
     * @return string
     */
    function osc_item_url_from_item($item, $locale = '')
    {
        if ( osc_rewrite_enabled() ) {
            $url = osc_get_preference('rewrite_item_url');
            if( preg_match('|{CATEGORIES}|', $url) ) {
                $sanitized_categories = array();
487:                $cat = Category::newInstance()->hierarchy($item['fk_i_category_id']);
                for ($i = (count($cat)); $i > 0; $i--) {
                    $sanitized_categories[] = $cat[$i - 1]['s_slug'];
                }
                $url = str_replace('{CATEGORIES}', implode("/", $sanitized_categories), $url);
            }
493            $url = str_replace('{ITEM_ID}', osc_sanitizeString($item['pk_i_id']), $url);
494            $url = str_replace('{ITEM_CITY}', osc_sanitizeString($item['s_city']), $url);
495            $url = str_replace('{ITEM_TITLE}', osc_sanitizeString($item['s_title']), $url);
            $url = str_replace('?', '', $url);
            if($locale!='') {
                $path = osc_base_url().$locale."/".$url;
            } else {
                $path = osc_base_url().$url;
            }
        } else {
            $path = osc_item_url_ns($item['pk_i_id'], $locale);
        }
        return $path;
    }
« Last Edit: July 27, 2017, 01:04:04 am by marius-ciclistu »

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: I'm getting php notices in my log files
« Reply #1 on: July 23, 2017, 12:20:01 am »
How and where do you use the function ?
Not the function itself is the problem , but the way is used .

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #2 on: July 23, 2017, 02:43:08 am »
I didn't changed the way osclass uses it in 3.7.1
« Last Edit: July 23, 2017, 02:44:46 am by marius-ciclistu »

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: I'm getting php notices in my log files
« Reply #3 on: July 23, 2017, 05:34:53 am »
it could be theme or plugin related

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #4 on: July 23, 2017, 10:46:33 am »
it could be theme or plugin related

I don't use plugins, so it's theme related... but I don't undertand why..those variables are from the table-database..and the function gives the url of the item, so it works fine.

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: I'm getting php notices in my log files
« Reply #5 on: July 23, 2017, 11:13:39 am »

maybe there are some empty variables delivered to this functions


you have to look where are this functions are called and why this vars are empty, but... this are just (mostly) harmless notices... you could ignore them

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #6 on: July 23, 2017, 11:25:49 am »
Maybe you are right but I noticed that the 4 table columns are from

oc_t_item
  - pk_i_id
  - fk_i_category_id
oc_t_item_description
   - s_title
oc_t_item_location
  - s_city

Does this mean anything?

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: I'm getting php notices in my log files
« Reply #7 on: July 23, 2017, 11:32:09 am »
of course... that means, that the affected file could be item.php  ;D

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #8 on: July 23, 2017, 11:45:07 am »
Ok. The only thing is that these lines in log files are using space on server . I had 240mb log file because I forgot to declare all the items of an array for a map hovering functionality that shoes the number of ads in a region (the regions with 0 ads gave the undefined warnings).
So if the site is visited by many people the log fills up ( even with notices).

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: I'm getting php notices in my log files
« Reply #9 on: July 23, 2017, 03:44:55 pm »
It's best to trap empty/''/null/isset/is_array values and handle them accordingly.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #10 on: July 23, 2017, 08:32:03 pm »
Not shure what you mean by that (I mean the actual code that does that), but this is related to the osclass 3.7.1 files, not to my modifications, so if I have them. someone else should have them. I don't know if in 3.7.3 they are still pressent.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: I'm getting php notices in my log files
« Reply #11 on: July 23, 2017, 09:17:55 pm »
That is correct, Osclass does have 'some' undefined notices, they are harmless but should really be taken care of in core code.
However, if you made changes in core than it IS possible these notices are related to those changes as well.

I think in 3.7.3 there still are similar notices in package.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #12 on: July 23, 2017, 09:35:51 pm »
I doubt my mods generated these notices.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: I'm getting php notices in my log files
« Reply #13 on: July 23, 2017, 10:02:44 pm »
Well you can simply add your own handling to get rid of these notices.

For instance on line 487 of hDefines you can add something like this:
If( isset(fk_i_category_id) ) {
.....
} else {
.....
}


marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #14 on: July 23, 2017, 10:57:07 pm »
But if we think about it....this function should construct the url.
Why is(should) this function called(be called) with a "half" item array?

It's description:  Create item url from item data without exported to view.

That "without exported to view" may be the reason for these notices?