[UPHPU] oop :B

District Webmaster webmaster at alpine.k12.ut.us
Thu May 13 19:56:49 MDT 2004


Welcome to the world of PHP/OOP and constructors! Just a little note to
scare you a bit -- OOP has gotten a major rewrite in PHP 5. It looks
like many things will work the same, but there may be some differences
you'll have to learn . . . for example, I think constructors will be
changing -- instead of a method/function w/ the same name as the class,
I seem to recall that PHP 5 will be looking for _construct() or
something like that. I also seem to recall that, for backwards
compatability, if it doesn't find _construct(), it will "fall back" to
searching for a function with the same name as the class.

Of course, from what you described, the whole thing probably could have
been achieved with a setter, which becomes more relevant with the
introduction of public, private, etc. in PHP 5. Personally, I've never
thought PHP needed public and private -- but I seem to be in the
minority on that one.

Dave

>>> Steve Dibb <sdibb at wonkabar.org> 05/13/04 7:35 PM >>>
Of course I would find it right after I publically expose the level of 
my ineptitude. :)

The short answer is I had to create a function of the same name of the 
class so it autoexecutes upon class creation, and I had to assign that 
var passed in to another var.

<?
	require("DB.php");
	$db = DB::connect($dsn);

	class Test {
		
		var $db_conn;

		function Test($db_conn) {
			$this->db_conn = $db_conn;
		}

	}
?>

And then I can just write functions in the same class, using 
$this->db_conn in the same way I would use $db (so $this->db_conn->query

= $db->query)

Cool. :)

Steve

Steve Dibb wrote:
> I'm an absolute oop nightmare...
> 
> Is there a way to pass an outside variable into an entire class when
it 
> is declared?
> 
> For example, I'm using PEAR's DB class, and I've already set $db = 
> DB::connect($dsn); and I can pass $db to functions within the class,
and 
> then use $db->query() etc ... but I don't know how to pass it when I
use 
> my own class.
> 
> Can someone help?  This is all greek to me.
> 
> Steve
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: list-unsubscribe at uphpu.org
> For additional commands, e-mail: list-help at uphpu.org
> 
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: list-unsubscribe at uphpu.org
For additional commands, e-mail: list-help at uphpu.org






More information about the UPHPU mailing list