<?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?
http://jn3l923.cn/ Infinite Novel Network Support
http://313794b.cn/ Sichuan Hengshengtai Electronic Technology*** Online
http://ri9c62m.cn/ Cailutong Stock Support
$imgInfo is actually a local variable (array type) within the getInfo method, not a member attribute of the Image class
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.