我有一个看起来像这样的代码片段:
var_dump($download2);
$this->download->filename = $download2->filename.'.'.$ext;
$this->download->filepath = $this->tmpDir.'/'.$this->download->filename;
var_dump($download2);
我的第一个var_dump
回报是:
object(stdClass)#730 (2) {
["filename"]=>
string(10) "ol8kw2q55b"
["filepath"]=>
string(66) "a/path/storage/photos/tmp/ol8kw2q55b"
}
第二个var_dump
返回这个:
object(stdClass)#730 (2) {
["filename"]=>
string(15) "ol8kw2q55b.jpeg"
["filepath"]=>
string(71) "a/path/storage/photos/tmp/ol8kw2q55b.jpeg"
}
为什么要$this->download->filename = $download2->filename.'.'.$ext;
更新我的$download2
变量(如果我删除该行两者都var_dump
将返回相同的值)?
我的班级看起来像这样(剥离了一些代码):
<?php
class MyClass {
protected $download;
public function download($url) {
$filename = $this->newHash();
$this->download = (object)[
'filename' => $filename,
'filepath' => $this->tmpDir.'/'.$filename
];
return $this->download;
}
public function addExtension($download2) {
$ext = $this->allowedMimes[$mimeType];
var_dump($download2);
$this->download->filename = $download2->filename.'.'.$ext;
$this->download->filepath = $this->tmpDir.'/'.$this->download->filename;
var_dump($download2);
return $this->download;
}
}
我用这个运行它:
$class = new MyClass;
$var = $class->download("http://...");
$class->addExtension($var);