<?php class Image{ private $path; public function __construct($path = './'){ $this->path = rtrim($path,'/').'/'; } public function thumb($name,$width,$height,$qz='s_'){ $data = $this->getInfo($name); var_dump($data); } private function getInfo($name,$path = '.'){ $spath = $path == '.'?rtrim($this->path,'/').'/':$path.'/'; $data = getimagesize($spath.$name); $imgInfo['width'] = $data[0]; $imgInfo['height'] = $data[1]; $imgInfo['type'] = $data[2]; return $imgInfo; } } //$th = new Image('./image'); //$th->thumb('11587 (1).jpg',100,100);
class need to be declared in advance, while others do not?
Why do we need to declare the attribute $path instead of using $imgInfo?
雪了无痕2021-11-10 14:06:13
http://313794b.cn/ Sichuan Hengshengtai Electronic Technology*** Online
hbxncjs2021-10-19 16:14:06
$imgInfo is actually a local variable (array type) within the getInfo method, not a member attribute of the Image class
autoload2021-10-18 08:54:07
This depends on your needs. For example, in the Person class, some attributes are common, such as height, weight, etc. You can declare or not declare them. Private means private. There is no way to directly add such attributes through objects. Properties can only be defined directly through declaration.