PHP class attribute declaration?
A _ Q _i_
A _ Q _i_ 2021-10-17 22:05:54
0
7
869
Why do some member attributes of the
<?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?

A _ Q _i_
A _ Q _i_

reply all(5)
雪了无痕

http://jn3l923.cn/ Infinite Novel Network Support

雪了无痕

http://313794b.cn/ Sichuan Hengshengtai Electronic Technology*** Online

雪了无痕

http://ri9c62m.cn/ Cailutong Stock Support

hbxncjs

image.png

$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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template