将数据传递给函数。 有什么更好的方法? [关闭]

Way 1:

public $foo = 1;
function(){
   return $this->foo+1;
}

Way 2:

// with $foo = 1 in other function
function($foo){
    return $foo+1;
}

Sorry for a 'dumb' question, someone can tell me what is the better way?

Second way is better and it is more canonical than first one. For more information please read this doc http://php.net/manual/en/functions.arguments.php