Passing Objects to other objects in PHP 4.3

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Juan_DomHonque
Forum Newbie
Posts: 1
Joined: Thu Mar 27, 2003 3:32 pm

Passing Objects to other objects in PHP 4.3

Post by Juan_DomHonque »

Hello,

I am having problems updating a script that worked in 4.1 to 4.3.


I have two objects, a database object and a item object. The item object needs to use the db object. Before I was passing the db object into the item object. Below is very basic code

Code: Select all

$db = new DB();
$item = new itemObject($db);
$item->doDB();

class itemObject {
  function __constructor($db){
     $this->db = $db;
  }

  function doDB(){
     $this->db-query("Select * from db");
  }
}
The above used to work but does not work in 4.3. How can I make this work?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<?php
class DB
{
// dummy DB-class
	function query($s)
	{
		echo $s, "<br />\n";
	}
}

class itemObject {
	var $db;
  
  function itemObject($db)
  {
     $this->db = $db;
  }

  function doDB()
  {
     $this->db->query("Select * from db");
  }
} 

$db = new DB();
$item = new itemObject($db);
$item->doDB();
?>
Post Reply