PHP: Can't pass the variable inside the class, why can't it be a class function?
-
distinguished experts!
Есть такой класс:
class Downloader
{
public $source_html, $dom;function __construct($source_html, $dom) { /* $this->source_link = $source_link; */ $this->source_html = $source_html; $this->dom = $dom; /* $this->xpath = $xpath; $this->open_config = $open_config; */
// $this->archives_names = $archives_names;
}public function getInfFromTheSource ($open_config) { $source_link = $open_config->InfSource; $source_html = file_get_contents($source_link); return($source_html); } public function selectWhatIsNeeded ($source_html) { $dom = new DOMDocument(); $dom->loadHTML($source_html); $xpath = new DOMXpath($dom); $archives_names = $xpath->query(''); return($archives_names); } public function downloadInFolder($open_config, $archives_names) { print_r($archives_names);
}
}
Copies of classes and challenges of methods create:
require_once 'Downloader.php';
$open_config = json_decode(file_get_contents('config.json', true));
$obj = new Downloader($open_config);
$obj->selectWhatIsNeeded($obj->getInfFromTheSource ($open_config));
$obj->downloadInFolder($open_config, $archives_names);
Why doesn't it work downloadInFolder()? The role select WhatIsNeed() is successfully filled with the variable $archives_names, but if you select WhatIsNeed(): print_r($archives_names); , the result is the empty screen of the browser. I'll be grateful for any advice!
-
require_once 'Downloader.php'; $open_config = json_decode(file_get_contents('config.json', true)); $obj = new Downloader($open_config); $archives_names = $obj->selectWhatIsNeeded($obj->getInfFromTheSource ($open_config)); $obj->downloadInFolder($open_config, $archives_names);
But you don't have to work because the designer requires two parameters, and it's moving one.
It is also unclear why the configuration should be kept constant if it is already preserved in class properties.