x1nick Posted December 17, 2010 Share Posted December 17, 2010 Struggling to get my head round this, may be really simple and im just not seeing it because im tired, but why does the following code generate two files? <?php class x { var $val = ''; var $cfg = array(); public function __construct($somevalue) { $this->val = $somevalue; file_put_contents(rand(0,1000).'init','null'); } public function addcfg($name,$value) { $this->cfg[$name] = $value; } } //Create $somevalue = 'abc'; $x = new x($somevalue); //Add database config $x->addcfg('name','dbname'); $x->addcfg('user','dbuser'); $x->addcfg('pass','dbpass'); Quote Link to comment https://forums.phpfreaks.com/topic/221935-class-construct/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2010 Share Posted December 17, 2010 Your browser is probably requesting the page twice. Firefox does this for 2-3 different reasons and other browsers do it as well for their own reasons. There are also reasons why the server will cause a file to be requested twice. Quote Link to comment https://forums.phpfreaks.com/topic/221935-class-construct/#findComment-1148481 Share on other sites More sharing options...
x1nick Posted December 17, 2010 Author Share Posted December 17, 2010 Ah thanks just tested in ie and chrome and issue doesn't exist! Now to work out how to get my logout function to work round this! As currently unable to destroy the session. Quote Link to comment https://forums.phpfreaks.com/topic/221935-class-construct/#findComment-1148491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.