For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > October 2004 > Passing an object as an argument









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Passing an object as an argument
Yiannis Koutros

2004-10-20, 8:55 pm

I hava a class that i use to connect with my db. After I instantiate the
class and I am connected with the database i save the connection link to a
property, which is a resource type.
I want to pass the whole object that i am creating and use the connection
inside another class. But when i do sth like the following there is a fatal
error that the mysql link is not a valid resource identifier.


class connection{
var $link;

function connect(){
$this->link = blalba
}
}

class thirdClass(){
var $connectionObject;

function thirdClass($connectionObject){
$this->connectionObject = $connectionObject;
}

function test(){
$this->connectionObject->executeQuery($query);
}

$myConnection = new Connection();
$myConnection->connect();

$myObject = new $thirdClass($myConnection);


I tried to serialize the object but that is meaningless as when you
serialize an object it is not saved the resource type.



Yiannis


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com