Page 1 of 1
for better way to make objects
Posted: Thu Dec 20, 2007 3:31 am
by crystal ship
Code: Select all
define ('DIRECTORY','../../../cis');
include ('queue.php');
function using($pathTree=NULL){
$objQueue = new Queue;
$objQueue->Queue();
$path=ereg_replace("\.","/",$pathTree).".php";
search($path,DIRECTORY,&$objQueue);
}
In the above code snippet I have to make $objQueue in every other functions that uses the search function inside it and also have to create a new stack. I have tried creating both object and queue outside the function
using but that dose not work. Could any one tell me the right way to handle this case.
Re: for better way to make objects
Posted: Thu Dec 20, 2007 4:23 am
by webspider
crystal ship wrote:Code: Select all
$objQueue = new Queue;
$objQueue->Queue();
is there any need to explicit call to the constructor? isn't Queue( ) constructor calling twice?
Posted: Thu Dec 20, 2007 4:25 am
by kaszu
define ('DIRECTORY','../../../cis');
include ('queue.php');
function using($pathTree=NULL){
$objQueue = new Queue;
$objQueue->Queue();
$path=ereg_replace("\.","/",$pathTree).".php";
search($path,DIRECTORY,&$objQueue);
}
I didn't understood what exactly is the problem and what are you trying to achieve, but you have syntax error in your code. I think following would be correct:
Code: Select all
define ('DIRECTORY','../../../cis');
include ('queue.php');
function using($pathTree=NULL){
$objQueue = new Queue();
$path=ereg_replace("\.","/",$pathTree).".php";
search($path,DIRECTORY,$objQueue);
}
function search($path, $folder, &$queue) {
....
}
Have you enabled error reporting?
Posted: Thu Dec 20, 2007 5:28 am
by crystal ship
Code: Select all
define ('DIRECTORY','../../../cis');
include ('queue.php');
function using($pathTree=NULL){
$objQueue = new Queue();
$path=ereg_replace("\.","/",$pathTree).".php";
search($path,DIRECTORY,$objQueue);
}
function search($path, $folder, &$queue) {
....
}
This code is working well but the problem is if I have to make another function like usingJs() for using javascript file then I again have to create an object inside the function usingJs. Similarly I have to create object in every function whereever I call the function search. Is there any way that I can solve it by creating it only once somewhere outside the function so that I can use the same object passing as a parameter.