Jump to content

Class construct


x1nick

Recommended Posts

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');

Link to comment
https://forums.phpfreaks.com/topic/221935-class-construct/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.