PHP类 - 公共变量在类外没有正确显示

In myClass I have declared $_total_results_found = 0

Then in my function I changed the value of $_total_results_found = 10

But, when I try to call this outside myClass the value still shows me 0.

Please can any one help me how to write this code?

class myClass
{
  private $_total_rows_count = 0;
  public function foundResults()
  {
    $count = 10;
    $this->_total_rows_count = $count;
  }
} // end myClass


$myclass = new myClass();
echo $myclass->_total_results_found; // Value is showing 0 instead of 10

Here you go:

<?
class myClass
{
  public $_total_rows_count = 0;
  public function foundResults()
  {
    $count = 10;
    $this->_total_rows_count = $count;
  }
} // end myClass


$myclass = new myClass();
$myclass->foundResults();
echo $myclass->_total_rows_count; //will print 10
?>

You haven't declared _total_results_found anywhere. The only variable you are using is _total_rows_count, which is private, so it's not accessible outside the class.