php如何访问函数内部的变量

I have function, say:

//file file1.php 
class p{
  function a(){
    global$v1;        
    $v1='';   
    //some processing to $v1 here//
    return $v1;
  }
}

How to access $v1? ($v1 in return $v1)

This is my try (in another file) :

//file file2.php
include 'file1.php';
$obj=new p();
$print=$obj->a()->$v1;
echo $print;

Why doesn't it print anything?

class p{
  function a($v1){
            ///some processing to $v1 here//
            return $v1;
        }
    }

Then pass your variable as a argument to your function.

//file file2.php
$v1 = 'Test';

require 'file1.php';
$obj=new p();
$print=$obj->a($v1);
echo $print;
<?php
//file file1.php 
class p{
  protected $v1;

    public function setP($v1){
     $this->v1 = $v1;
    }

  public function getP(){

    $this->setP('');   
    ///some processing to $v1 here//
   return $this->v1;
   }
}

$obj = new p();
$print = $obj->getP();
echo $print;
?>