Php方法没被调用

I have been trying to debug this code for a while now, and it looks like the build method is not being called. I put echo's, var_dumps, and all other kinds of signs in it, but never get anything.

Full php code

class Auto_slideshow {

  private $_img_dir;

  //constructor sets directory containing the images
  function __construct($dir) {
    //Directory source from webroot
    $_img_dir = $dir;
  }

  //Iterates through directory and constructs HTML img list
  public function build() {

    //use SPL for directory iteration
    $iterator = new DirectoryIterator($_img_dir);

    $html = '';
    $i = 1;

    //Iterate through directory
    foreach ($iterator as $file) {

      //set a variable to add class of "show" on first element
      $showClass = $i === 1 ? ' class="show"' : null;

      //exclude '.' and '..' files
      if(!$iterator->isDot()) {

        //set src attribute for img tag
        $src = $_img_dir . $iterator->getFilename();

        //Grab sizes of images
        $size = getimagesize($_img_dir . $iterator->getFilename());
        var_dump($src);
        //create img tags
        $html .= '<img src="' . $src . '" ' . $size[3] . $displayNone . ' />' . "
";

        $i++;
      }
    }

    return $html;
  } 
}

html call

<center>
    <div class="imagecontainer" id="auto-slideshow">
    <?php
    $show = new Auto_slideshow("../CMSC/images/master/slidestock/");
    $show->build();
    ?>
</div>
</center>

I also tried print $show->build();, as the tutorial showed, which also did not work.

Update

I changed $_img_dir to $this->$_img_dir' and called the method byecho show->build();` and the method still isn't being called.

This is a matter of the method not even running, not even to the point of find the images yet.

Update 2

If I remove the entire php code within the html, the rest of the page loads just fine. As it is now, the html loads only to the div that contains the php then stop everything after it.

Fix and update the code bellow:

Constructor:

$this->_img_dir = $dir;

build Function:

$iterator = new DirectoryIterator($this->_img_dir);

$src = $this->_img_dir . $iterator->getFilename();

$size = getimagesize($this->_img_dir . $iterator->getFilename());

You can call it:

echo $show->build();

Have you used a var_dump() outside of the loop as well?

The problem is that your variable will remain NULL:

  //constructor sets directory containing the images
  function __construct($dir) {
    //Directory source from webroot

    // This is a local variable that will be gone when the constructor finishes:
    $_img_dir = $dir;
  }

You need:

  //constructor sets directory containing the images
  function __construct($dir) {
    //Directory source from webroot
    $this->_img_dir = $dir;
     ^^^^^^ here
  }

You return the text you want to display but you don't display it:

echo $show->build();