Advertisement:

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

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: I'm getting php notices in my log files
« Reply #15 on: July 23, 2017, 11:08:56 pm »
Welcome in the twilight zone ;)

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: I'm getting php notices in my log files
« Reply #16 on: July 24, 2017, 12:20:34 am »
 Do a var_dump before calling the function . You will find the reason of notices

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 #17 on: July 24, 2017, 01:18:08 am »
Do a var_dump before calling the function . You will find the reason of notices

You are right..if only I could identify on which item these notices apear, because the url's are working fine and the notices apear only from time to time.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: I'm getting php notices in my log files
« Reply #18 on: July 24, 2017, 03:04:50 am »
It is really not an issue once you start adding the check, this is normal depending on the way certain functions are designed. You can have situations where a certain variable is 'missing' by design and causing an undefined notice due to the fact the scenario is not taken care of in code the way php would like it to be. This is what the check is for, if isset.... it doesn't mean there is actually an error to be fixed.

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 #19 on: July 24, 2017, 09:42:47 am »
It is really not an issue once you start adding the check, this is normal depending on the way certain functions are designed. You can have situations where a certain variable is 'missing' by design and causing an undefined notice due to the fact the scenario is not taken care of in code the way php would like it to be. This is what the check is for, if isset.... it doesn't mean there is actually an error to be fixed.

So you are saying:
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:       if( isset($item["fk_i_category_id"]) ) {          $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            if( isset($item["pk_i_id"]) ) {      $url = str_replace('{ITEM_ID}', osc_sanitizeString($item['pk_i_id']), $url); }
494            if( isset($item["s_city"]) ) {       $url = str_replace('{ITEM_CITY}', osc_sanitizeString($item['s_city']), $url); }
495            if( isset($item["s_title"]) ) {       $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;
    }

But what happens when they are undefined?


Or you meant:

Code: [Select]
487:       if( isset(fk_i_category_id) ) {          $cat = Category::newInstance()->hierarchy($item['fk_i_category_id']);    }
....

But in this whay I think that it will never validate, because the argument is not a defined variable in that function, or globally
« Last Edit: July 24, 2017, 02:06:02 pm by marius-ciclistu »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: I'm getting php notices in my log files
« Reply #20 on: July 24, 2017, 01:49:08 pm »
What you do by adding the check is preventing the notice from occuring in your log file.
PHP will kind of do the same, in case a variable is not set there is nothing it can do but because it is not checked in code and handled properly it throws the 'undefined notice' in your logfile and it simply continues the code ignoring the undefined variable simply because it is not there in the specific scenario.

The first part is correct, you can see that a function is called using: $item["fk_i_category_id"]
It is the whole part here that return a category id (or not) in case it is 'missing' (not set) it means that the array variable $item is either missing the specific field fk_i_category_id or simply missing completely.

So you check on $item["fk_i_category_id"] resulting in; if( isset($item["fk_i_category_id"]) ) {
If it is NOT set that part of code related to the processing of $item["fk_i_category_id"] gets skipped resulting in a clean log file and for your code there is no change in how it worked before adding that check. If there is an issue caused earlier that was already there it will still be there. You only prevented the undefined notice by handling the scenario of a missing variable here correctly.

So, with regard to the 'cause', the $item["fk_i_category_id"] not being set most likely means that the $item array is not set which would explain the other three notices related to this function.

Meaning, this function got called without $item being properly populated with it's array values, meaning earlier in code there is a scenario where this function gets called while $item is/was not set which can be due to a code architecture ie. the first time it is not yet ready for handling but after the first loop it is...... or something else. The cause is no so important if the whole system does its work but it could be done better probably preventing the scenario from happening but this is how it is at the moment and best thing to do is 'trap' those scenario's with isset (or another check for '' as well) so PHP is satisfied with the syntax and proces flow.

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 #21 on: July 24, 2017, 02:18:00 pm »
Got it. I'll do the mods and wach what happens. T Y.

Until now, I've "patched" so many tiny things like this in the files....sometimes I think that osclass was specialy built for me to learn more and more php :)

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 #22 on: July 24, 2017, 02:30:11 pm »
I made them.
Curios. The last 2 sets of notices were:

[23-Jul-2017 23:09:29 ] PHP Notice:  Undefined index: fk_i_category_id in /oc-includes/osclass/helpers/hDefines.php on line 487
[23-Jul-2017 23:09:29 ] PHP Notice:  Undefined index: pk_i_id in /oc-includes/osclass/helpers/hDefines.php on line 493
[23-Jul-2017 23:09:29 ] PHP Notice:  Undefined index: s_city in /oc-includes/osclass/helpers/hDefines.php on line 494
[23-Jul-2017 23:09:29 ] PHP Notice:  Undefined index: s_title in /oc-includes/osclass/helpers/hDefines.php on line 495
[24-Jul-2017 03:14:55 ] PHP Notice:  Undefined index: fk_i_category_id in /oc-includes/osclass/helpers/hDefines.php on line 487
[24-Jul-2017 03:14:55 ] PHP Notice:  Undefined index: pk_i_id in /oc-includes/osclass/helpers/hDefines.php on line 493
[24-Jul-2017 03:14:55 ] PHP Notice:  Undefined index: s_city in /oc-includes/osclass/helpers/hDefines.php on line 494
[24-Jul-2017 03:14:55 ] PHP Notice:  Undefined index: s_title in /oc-includes/osclass/helpers/hDefines.php on line 495

The ones from 3:14:55 i think were created by a boot or something.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: I'm getting php notices in my log files
« Reply #23 on: July 24, 2017, 09:21:10 pm »
This is how I learned and still am learning. :)
Reading back I start doubting myself if it is correct that the code continues or simply silently (with a notice) stops.... ohwell, will have to Google this to be sure.

Got it. I'll do the mods and wach what happens. T Y.

Until now, I've "patched" so many tiny things like this in the files....sometimes I think that osclass was specialy built for me to learn more and more php :)

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 #24 on: July 24, 2017, 09:22:13 pm »
Until now the notices did not reapear.
Edit
And the function is working - i modified the s_title to  removeunderline(item['s_title']) so that the under 4 characters words don't apear with underlines and it's ok. It was like this before the isset code to be inserted.

EDIT: if the item array is not complete the function has no sense. Why generate an url for an incomplete item? And I checked the db of items. There is none without pk_i_id and fk_i_category.
« Last Edit: July 24, 2017, 09:32:07 pm by marius-ciclistu »

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: I'm getting php notices in my log files
« Reply #25 on: July 24, 2017, 09:36:34 pm »
Enable sql debug to see what querry is  not getting results
https://doc.osclass.org/Debug_SQL_queries

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 #26 on: July 24, 2017, 09:50:06 pm »
Wait!! I made a change and all items must be unblocked by the admin after posting, so when an item is created, it is blocked by default.
Then the admin gets an email containing including the item's url. Could it be that that is the source for this notices?I'll test now.

So. I published the ad.
The 2 fields pk_i_id and fk_i_category from oc_t_item table are there with values;
in oc_t_description the s_title  and in oc_t_location the s_city are also there with values.

After item unlock these fields do not change......

So this is not the reason....

Could it be that this is happening after the item is deleted?

I also modified the script to send an email to the user after it's ittem is unlocked. Then this function is being triggered... but I can't remember being so fast to unlock and then delete the item...
« Last Edit: July 24, 2017, 09:58:27 pm by marius-ciclistu »

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 #27 on: July 24, 2017, 09:56:49 pm »
Enable sql debug to see what querry is  not getting results
https://doc.osclass.org/Debug_SQL_queries
I did that now and I"ll wait and see.

EDIT:

What to look for? I created and deleted an item.

The logs were generated
« Last Edit: July 24, 2017, 10:11:29 pm by marius-ciclistu »

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 #28 on: July 25, 2017, 12:22:42 am »
Until now the notices didn't reapear. It's curious that the other night at 3 am the notices apeared.. noone posted an ad at that time... noone else had this notices?

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: I'm getting php notices in my log files
« Reply #29 on: July 25, 2017, 01:43:42 am »
What page do use that function ? Is used in a theme ?   Core  only ? Can you post some code here  if theme file ?
Search page ? Different categories , different views ? (Grid,list)
 Enter that page ..  check logs .. sql logs .
The osc_item_url_from_item is a helper function .
 It is called  only inside  osc_item_url  function , and  do use item from exported view 
Code: [Select]
/**
     * Create automatically the url of the item details page
     *
     * @param string $locale
     * @return string
     */
    function osc_item_url($locale = '')
    {
        return osc_item_url_from_item(osc_item(), $locale);
    }
in my setup is used  322 times admin and front-end ,so any page  that do use items can throw that notices .
« Last Edit: July 25, 2017, 02:36:51 am by Web-Media »