WordPress oddity with broken images (part 1)

Can you tell me your opinion of this, and possibly see if you can recreate it:

Currently, the $post->post_content variable contains:

Read More
"before <img src="/path/to/valid_img.gif" /> after"

This code placed at the top of the theme header.php…

------ Code --------
    1: $str = $post->post_content;
    2: assert( isset( $str ) );
    3: assert( is_string( $str ) );
    4: echo $str;
    5: $str = 'before <img src="/path/to/nonexistant.gif" /> after';
    6: assert( isset( $str ) );
    7: echo $str;
--------------------

Outputs this…

------ Output ------
before <img src="/path/to/valid_img.gif" /> after
before <img src="/path/to/nonexistant.gif" /> after
--------------------

With these warnings…

--- PHP Warnings ---
PHP Warning:  assert() [<a href='function.assert'>function.assert</a>]: Assertion
failed in /path/to/header.php on line 2
PHP Warning:  assert() [<a href='function.assert'>function.assert</a>]: Assertion
failed in /path/to/header.php on line 3
--------------------

Why would line 4 properly echo the $str if assert() fails twice when I KNOW 100% it should succeed?

What does a broken image src have to do with setting or unsetting the variable $str? WordPress bug/oddity?

Now the crazy part…

When lines 5-7 are commented out, thus eliminating the nonexistant.gif, the assert() warning does NOT appear and the output STILL properly produces this…

------ Output ------
before <img src="/path/to/valid_img.gif" /> after
--------------------

Any chance you can reproduce this and tell me what you think? I’m new to PHP, but I’m pretty sure this is crazyness. 🙂

Related posts

Leave a Reply

2 comments