T
T
thorii2016-08-26 15:57:54
PHP
thorii, 2016-08-26 15:57:54

What is the problem with implicit behavior when creating two instances of the same class?

class someClass 
{

private $prefix = 'prefix_';
private $str;

function __construct($data) 
{
$this->str = $this->prefix.$data;
var_dump($this);
}
}
//Это в другом файле соответственно
$one = new someClass('data');
$two = new someClass('AnotherData');

When creating a second instance inside the class, $prefix
DUMP seems to disappear:
$one = string "prefix_data";
$two = string "AnotherData";
Probably just don't know how to google properly

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tzlom, 2016-08-26
@thorii

require_once includes the file only once, on the second call the file is not included and $$config does not exist

A
Arthur, 2016-08-26
@ArturF

$this->str = $prefix.$data; -> $this->str = $this->prefix . $data; maybe?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question