Re: One class, many methods: PHP4.x: Q's

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Davey wrote:
Within the constructor for Randimg you could set a local protected variable:
class Randimg
{
  var $docroot = false;

  function Randimg ()
  {
    $this->docroot = $_SERVER['DOCUMENT_ROOT'];
  }

Hi Rich and all, just one other quick question...

Which approach below would you choose?

Example 1:

class Randimg {
	# Initialize var variables:
	var $foo1 = FALSE;
	var $foo2 = FALSE;
	var $foo3 = TRUE;
	# Constructor:
	function Randimg {
		$this->foo1 = TRUE;
		$this->foo2 = TRUE;
		$this->foo3 = FALSE;
		return $this->method_foo();
	}
	function method_foo() {
		$x = $this->$foo1;
		$y = $this->$foo2;
		$z = $this->$foo3;
		/* Do stuff... */
		return $x.$y.$z;
	}
}

Example 2:

class Randimg {
	# Constructor:
	function Randimg {
		$foo1 = TRUE;
		$foo2 = TRUE;
		$foo3 = FALSE;
		return $this->method_foo($foo1, $foo2, $foo3);
	}
	function method_foo($x, $y, $z) {
		/* Do stuff... */
		return $x.$y.$z;
	}
}

Hopefully my syntax is decent... I am guessing the approach I take depends on the needs of my script. Setting local protected variables seems like it would work well for my latest project, but is that bad programming practice to rely upon local protected variables when it comes to passing variables between methods?

Seems like I have always read/heard that it is best to explicitly pass variables as function parameters... vs throwing around "globals."

Sorry if silly questions. :)
Thanks again!
Cheers,
M


--
Wishlists: <http://snipurl.com/1gqpj>
   Switch: <http://browsehappy.com/>
     BCC?: <http://snipurl.com/w6f8>
       My: <http://del.icio.us/mhulse>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux