|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-06-04 14:10 UTC] full_ot at directbox dot com
Description:
------------
System: Win2k SP4, Apache 2.0.49 PHP 4.3.6
(also tested on Win2k SP4, Apache 2.0.48 PHP 4.3.4 with same result)
I have a class that handle news in a CMS. So it also have to save the news in single files.
The srcipt below is the essence of that class. But it seems to run twice, because the save-function creates two files with different timestamps. Regardless it is only called once.
If u use the first line of show() all is working fine, but the second line with the img-tag causes trouble.
The variable $image_url ist know to the class but its uninitialized. Nevertheless this shouldnt cause such unexpected behaviour.
Reproduce code:
---------------
class news{
var $image_url, $timestamp;
function show(){
// echo $this->image_url; echo $this->image_url; //working fine (returns nothing, create one file)
echo "<img src=\"".$this->image_url."\" alt=\"".$this->image_url."\">"; //this causes the script to run twice
}
function save(){
$fp = fopen($this->timestamp, "w");
fclose($fp);
}
}
$news = new news;
$news->timestamp = microtime();
$news->save();
$news->show();
Expected result:
----------------
It should save one! file to disk and print nothing on the screen (cause $image_url is empty). The name of the file is the timestamp of its creation.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 20:00:01 2025 UTC |
same behavior on my system: Windows NT BERT 5.1 build 2600 Apache: Apache/2.0.49 (Win32) PHP: PHP/4.3.6 This seems to be a browser thingy and not a bug: the php-skript gets simply called twice as u write a <img> tag with empty src. The browser tried to load the image from the same url. just initialize $image_url with an non-empty but invalid value, like: ======================================================= class news { var $image_url, $timestamp; function news() { // constructor $this->image_url = "none.gif"; $this->timestamp = microtime(); } ........... =========================================================