Home › Forums › MapPress Support › Issue and Potential Fix Regarding Property Access in Mappress_Poi Class
Tagged: Bug with POI php integration
- This topic has 2 replies, 2 voices, and was last updated 2 years, 9 months ago by
Myluxurytravel.
-
AuthorPosts
-
November 5, 2023 at 6:56 pm #20511
Hi Support,
I’ve encountered an issue with the MapPress Maps plugin that I wanted to share with you, along with a potential fix. The goal was to create a dynamic map using MapPress, with Points of Interest (POIs) specified dynamically through our PHP code,
Issue:
When utilizing the plugin, PHP Notices are being generated regarding attempts to access properties on a non-object within the mappress_poi.php file:PHP Notice: Trying to get property ‘lat’ of non-object in /path_to_file/mappress_poi.php on line [line_number]
PHP Notice: Trying to get property ‘lng’ of non-object in /path_to_file/mappress_poi.php on line [line_number]Upon investigating the code, it seems like the issue is occurring in the to_html() method where $this->point is being accessed as if it’s an object:
$vars->point = (isset($this->point)) ? $this->point->lat . ‘,’ . $this->point->lng : ”;
However, within the Mappress_Poi class, $point is declared and initialized as an associative array:
$point = array(‘lat’ => 0, ‘lng’ => 0);
This discrepancy in access method vs. declaration seems to be the root cause of the issue.Proposed Fix:
Modifying the to_html() method to access $this->point as an array appears to resolve the issue without generating the PHP Notices:$vars->point = (isset($this->point)) ? $this->point[‘lat’] . ‘,’ . $this->point[‘lng’] : ”;
Request:
Could you please consider validating and possibly incorporating this adjustment in a future plugin update to prevent the aforementioned PHP Notices from occurring? The modification aligns with the current variable type declaration and seems to be coherent with the intended use of $point.November 5, 2023 at 6:58 pm #20537Hi,
I’m sorry I didn’t respond sooner. The warning notice doesn’t appear on my test sites. How are you generating the maps? Are you using PHP, or a shortcode, or a block?
In any case, this should be fixed in 2.88.9, which should accept both arrays and objects.
November 12, 2023 at 12:30 pm #20553Hi there. yes it was with php.
-
AuthorPosts
- You must be logged in to reply to this topic.
