Answer the question
In order to leave comments, you need to log in
How to get rid of variables when calling methods?
Here is my class (yes bike and all your other terms):
class Picture
{
public $size = 500000;
public $type = array("image/jpg","image/png","image/jpeg");
public function getPic($file){
if($file['image']['size'] <= $this -> size){
return $file;
}
else {
return 'Размер изображения превышен';
}
}
public function getType($file){
if(in_array($file['image']['type'],$this -> type)){
return $file;
}
else {
return 'Неверный тип изображения';
}
}
}
$image = new Picture();
$getPic = $image -> getPic($_FILES);
$type = $image -> getType($getPic);
$name = 'img';
var_dump( $image -> setName($type, $name));
Answer the question
In order to leave comments, you need to log in
what's the problem with passing variables to a method?
set them in the constructor.
class MyClass{
protected $imgObj;
public function __construct(){
$this->imgObj = new Image();
}
public function otherFunction(){
$name = $this->imgObj->getName();
}
}
public function __construct(Image $image){
$this->imgObj = $image;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question