Undefined variable in oembed.php

Post

Posted
Rating:
#3724 (In Topic #743)

Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php on line 133

Greetings,

On a newer install with not much content I somehow have crashed the system with an error code of :

in ADMIN area:  PHP NOTICE [8] Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php on line 133 (version: 10.0.12, PHP version: 7.2.1-1+ubuntu16.04.1+deb.sury.org+1, URL: /adminzone/index.php?page=admin-cleanup&type=rebuild)

main page:

PHP NOTICE [8] Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php on line 133 (version: 10.0.12, PHP version: 7.2.1-1+ubuntu16.04.1+deb.sury.org+1, URL: /index.php?page=start)

History:
1. I had posted a few links to facebook pages and was surprised that the oembed did not work as usual. I ignored it and wanted to investigate in the future. 
2. Today I posted a new news item with a FB link and the system crashed. I deleted that news article.
3. I am attempting to delete the sole news article but no luck.

Since this is a new install with no content I can just restart fresh but wanted to share this as maybe it is a bug or something on my end.

Thanks much

Stevyn


 

Post

Posted
Rating:
#3725
I suspect your sources/hooks/systems/media_rendering/oembed.php file has been corrupted somehow. It's very unusual for a PHP file to be corrupted in Composr, unless it was hand-edited wrongly somehow.

Anyway, re-uploading that file should fix the error.

Post

Posted
Rating:
#3735
Hello,

I downloaded the latest zip and uploaded all files to be safe. Then cleared the caches and ran file integrity check and all checks out as good. I also did a check on the database and it says each table is OK.

I still have the error as you can see at (link removed by stevyn)

Should I post the full error report? (seen only when admin is logged in?

Thank you

Stevyn

PS: this is super low priority since the site is newish, I could just replace the database and start with a new database? or purge the news in the database?
 

Last edit: by ironfeather


Post

Posted
Rating:
#3736
It's really bizarre. I can trace that variable through the code and it's definitely defined. Maybe some weird opcode cache extension bug.

If you'd like me to debug on the server itself, please send FTP access to [email protected].

I'd like to track it down.

Post

Posted
Rating:
#3737
Hello,

I should mention more details

1. I had a few news articles and some had FB links
2. Under the news I edited the inner zone page and added two FB links and for a few days they worked normally, the composr oembed would display them as they should (expanded FB feed) then suddenly it didnt work and were simply just links again.
3. I was not sure why they didnt work so I left them alone but edit the zone editor again and this time manually embedded the HTML from facebook to display a feed. THis worked but the normal links stayed as links
4. I posted a new news article and in the new article had a new facebook link, thehn everything went haywire as we see now. 

Could the manual useage of FB embed screw it up?

Thanks for helping

Stevyn

PS* I emailed you access info. Thank you


 

Post

Posted
Rating:
#3740
Looking at this now.

Post

Posted
Rating:
#3741
Hi,

It's fixed now, but it's definitely a bug in a PHP extension or PHP itself. Most likely Zend OpCache, which I think is undefining a variable we are using because it incorrectly thinks it won't be used again. But your server also has a couple of non-official PHP extensions which could also potentially be causing some memory corruption (msgpack, igbinary). I can't say for sure the cause.

I worked around it by rearranging the code. Arguably my rearrangement is a bit cleaner, so I don't mind doing that.

For reference here is the change I made…

Code (Diff)

diff --git a/sources/hooks/systems/media_rendering/oembed.php b/sources/hooks/systems/media_rendering/oembed.php
index 3eabb3274..6e6763fd1 100644
--- a/sources/hooks/systems/media_rendering/oembed.php
+++ b/sources/hooks/systems/media_rendering/oembed.php
@@ -112,11 +112,6 @@ class Hook_media_rendering_oembed extends Media_renderer_with_fallback
         }
 
         // Work out the full endpoint URL to call
-        $format_in_path = (strpos($endpoint, '{format}') !== false);
-        $preferred_format = 'json';
-        if ($format_in_path) {
-            $endpoint = str_replace('{format}', $preferred_format, $endpoint);
-        }
         if (strpos($endpoint, '?') === false) {
             $endpoint .= '?url=' . urlencode($url);
         } else {
@@ -130,7 +125,11 @@ class Hook_media_rendering_oembed extends Media_renderer_with_fallback
         if ((!array_key_exists('height', $attributes)) || ($attributes['height'] != '')) {
             $endpoint .= '&maxheight=' . urlencode(array_key_exists('height', $attributes) ? $attributes['height'] : get_option('oembed_max_size'));
         }
-        if (!$format_in_path) {
+        $format_in_path = (strpos($endpoint, '{format}') !== false);
+        $preferred_format = 'json';
+        if ($format_in_path) {
+            $endpoint = str_replace('{format}', $preferred_format, $endpoint);
+        } else {
             if (strpos($endpoint, '&format=') === false) {
                 $endpoint .= '&format=' . urlencode($preferred_format);
             }
 

I also noticed a simpler change worked, changing $format_in_path = (strpos($endpoint, '{format}') !== false); to $format_in_path = (strpos($endpoint, '{format}') !== false) && true;, but that was messy, I didn't like it (or understand why it could fix it).

Last edit: by Chris Graham

Post

Posted
Rating:
#3742
Oh yes, and I forgot to mention…

Ideally in a situation like this I'd isolate the issue down to a test case to report to PHP. However, I tried and failed to do that, so it must have been a somewhat complex issue, e.g. the optimizer kicking in after multiple calls into the code. Almost certainly someone will find and fix it in due to time though.

Post

Posted
Rating:
#3762
Thank you very much for your help and taking the extra time to research and track it down.

The site is back up and I am excited to continue working on it.

Thanks again, you rock!

Stevyn

 

Post

Posted
Rating:
#3886
Hello, sorry to bring this back up…

I just upgraded from 12 to 13 and was surprised to see that the oembed didnt work.  So did a file integrity check and got:  

These files do not match the ones bundled with your version, but claim to be newer (so these might be bug fixes someone has put here):

sources/hooks/systems/media_rendering/oembed.php

which is the fix you did…. so i removed it and uploaded the newer oembed.php from the latest 13 version and still no luck sadly…

Not sure what has happened

Post

Posted
Rating:
#3960
Oh dear (and sorry for the delayed reply).

Is it the same error message, "Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php"?

Likely what has happened is that because other PHP code has changed, whatever weird PHP bug is happening has shifted. It could be some kind of memory overwrite issue in PHP, or something to do with a PHP optimiser extension, and those kinds of things are very unpredictable.

I am happy to look again. If you can get a URL for me to test case that would help (e.g. to a news post or something where this is showing). Feel free to email me.

Post

Posted
Rating:
#3969
Hello,

It works fine on my main site (different server) and none else are posting about it so I think the server I setup has some php problems....  I will try and remove all php and install fresh and see if that will fix it.

Will report back

Thank you for the help, really appreciate it.

 

2 guests and 0 members have recently viewed this.