php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28630 unset class-variable combinated with echo causes script to run twice
Submitted: 2004-06-04 14:10 UTC Modified: 2004-07-06 01:32 UTC
From: full_ot at directbox dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.6 OS: Win2k
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: full_ot at directbox dot com
New email:
PHP Version: OS:

 

 [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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-08 10:55 UTC] 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-08 11:25 UTC] m dot tschursch at ic3s dot de
browser used: mozilla firefox 0.7
 [2004-07-06 01:32 UTC] sniper@php.net
User/browser error, nothing to do with PHP.

 [2023-01-28 00:06 UTC] alfandy at gmail dot com
Thanks you for post, same problem is now resolved.
(https://www.4flix.co)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 11 11:01:27 2024 UTC