dongshou7903 2009-07-22 14:44
浏览 38
已采纳

WordPress奇怪与破碎的图像(第1部分)

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

Currently, the $post->post_content variable contains:

"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. :)

  • 写回答

2条回答 默认 最新

  • drfm55597 2009-07-22 14:50
    关注

    assert() makes no sense in your code, what you want is an if statement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效