Bug #28630 [Com]: unset class-variable combinated with echo causes script to run twice
| From: | alfandy at gmail dot com | Date: | Sat, 28 Jan 2023 00:06:36 +0000 |
| Subject: | Bug #28630 [Com]: unset class-variable combinated with echo causes script to run twice | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-243583@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=28630&edit=1
ID: 28630
Comment by: alfandy at gmail dot com
Reported by: full_ot at directbox dot com
Summary: unset class-variable combinated with echo causes
script to run twice
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Win2k
PHP Version: 4.3.6
Block user comment: N
Private report: N
New Comment:
Thanks you for post, same problem is now resolved.
(https://www.4flix.co)github.com
Previous Comments:
------------------------------------------------------------------------
[2004-07-06 01:32:23] sniper@php.net
User/browser error, nothing to do with PHP.
------------------------------------------------------------------------
[2004-06-08 11:25:57] m dot tschursch at ic3s dot de
browser used: mozilla firefox 0.7
------------------------------------------------------------------------
[2004-06-08 10:55:34] m dot tschursch at ic3s dot de
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();
}
...........
=========================================================
------------------------------------------------------------------------
[2004-06-04 14:10:10] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=28630&edit=1