oop - variables scope in php -


why can define new instance of class adrequest inside function this:

require_once 'adrequest.php'; class adrequesttest extends phpunit_framework_testcase{    public $fixture;    function testgethash_returnscorrectvalue(){     $fixture = new adrequest();     $fixture->site = "dummy.com";   } } 

but when trying create instance this:

require_once 'adrequest.php';  class adrequesttest extends phpunit_framework_testcase{    public $fixture;   $fixture = new adrequest();    function testgethash_returnscorrectvalue(){     $fixture->site = "dummy.com";   } } 

i got error:

php parse error: syntax error, unexpected '$fixture' (t_variable), expecting function (t_function)

if want create instance once , use in every function , use setup() , setup() called before each testxxx() method

<?php  require_once 'adrequest.php'; class adrequesttest extends phpunit_framework_testcase{   public $fixture;   public function setup() {      $this->fixture = new adrequest();  }   function testgethash_returnscorrectvalue(){      $this->fixture->site = "dummy.com";  } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -