|
Posted by "Ian Barnes" on 09/08/05 17:01
Hi Thomas,
Thanks for the help. That didn't work though ...
Its now set to be $SDK = new sdk;
Nothing :(
-----Original Message-----
From: Thomas [mailto:tomatosh@gmail.com]
Sent: 08 September 2005 09:08 AM
To: 'Ian Barnes'
Subject: RE: [PHP] Help with Class
Sorry for not explaining ... [code]$SDK =& new ipbsdk;[/code] initializes
the $SDK variable as a reference of the class ipbsdk. The '&' operator is
called the reference operator. So by leaving it out you copy (the default
initialization) the resulting class object.
Maybe that does the trick.
T
-----Original Message-----
From: Ian Barnes [mailto:ian@opteqint.net]
Sent: 08 September 2005 08:52 AM
To: 'Thomas'
Subject: RE: [PHP] Help with Class
Sorry for the stupid question. How do I init the class as a copy not a
reference ?
-----Original Message-----
From: Thomas [mailto:tomatosh@gmail.com]
Sent: 08 September 2005 08:25 AM
To: 'Ian Barnes'
Subject: RE: [PHP] Help with Class
Hmm, that is strange because OO tells us that by nulling an object you
destroy it. I don't see what the other person could have done to avoid the
destruction of his class ... (that would be above my head)
One more thing I would try (which you have not done yet) is to initialize
the class as a copy and not a reference. That should not impair your code
much because you are creating a new one ever time anyway.
> think it cant be done
That would somehow go against my understanding of OO programming ;-) ...
Good luck.
Thomas
-----Original Message-----
From: Ian Barnes [mailto:ian@opteqint.net]
Sent: 08 September 2005 08:07 AM
To: 'Thomas'
Subject: RE: [PHP] Help with Class
Hi,
I put the db object in there temporarily because the SDK class resets it and
I haven't gotten round to changing it yet.
I tried initing $SDK to null at the start but that hasn't worked either.
The class that I initing isn't mine, it was written by someone else and they
don't allow for multiple directories. The first run in the foreach loop runs
perfectly, I get all the info back I need, so its just when the loop runs
again.
Here is my current code with all options I have tried:
foreach ( $forums as $num=>$val )
{
$SDK=null;
$sdk = null;
$db = new db ( 'localhost' , 'user' , 'pass' , 'db' );
$sql = 'SELECT * FROM vaults WHERE id = "'.$val.'"';
$result = $db->get($sql);
$fetchd = mysql_fetch_array ( $result );
$forumid = $fetchd['forumid'];
$posterid = $fetchd['posterid'];
$title = $_POST['title'];
$desc = $_POST['desc'];
$post = $_POST['post'];
require_once ( $fetchd['path'].'sdk/ipbsdk_class.inc.php' );
$SDK =& new ipbsdk;
$info = $SDK -> get_info ( $posterid );
$postername = $info['name'];
echo "Forum ID:".$forumid;
echo "<BR>Title:".$title;
echo "<BR>Desc:".$desc;
echo "<BR>Post:".$post;
echo "<BR>PosterID:".$posterid;
echo "<BR>PosterName:".$postername;
echo "<BR>";
// if ($SDK -> new_topic($forumid, $title, $desc, $post, $posterid,
$postername)) {
// echo 'Topic Created!';
// } else {
// echo $SDK->sdk_error();
// }
unset ( $sdk );
$SDK = null;
unset ( $SDK );
$sdk = null;
unset ( $GLOBALS['SDK']);
unset ( $GLOBALS['sdk'] ) ;
$GLOBALS['SDK'] = null;
$GLOBALS['sdk'] = null;
$_SESSION['sdk'] = null;
$_SESSION['SDK'] = null;
unset ( $_SESSION['SDK'] );
unset ( $_SESSION['sdk'] );
register_shutdown_function($SDK);
register_shutdown_function($sdk);
}
So as you can see, I have tried a lot of things and im starting to think it
cant be done, in which case ill just have to take the other persons class
and either modify it (which is against his terms) or take what he does and
do it manually myself.
Thanks for the help.
Ian
-----Original Message-----
From: Thomas [mailto:tomatosh@gmail.com]
Sent: 08 September 2005 07:54 AM
To: 'Ian Barnes'
Subject: RE: [PHP] Help with Class
First up, I am not sure if you need to create a new db object every single
loop, as far as I can see you can easily leave that outside the loop (unless
you connect to a different db on each loop).
Maybe you could initialize the $SDK variable on top of your loop with null
($SDK=null;) that way ever loop will serve you up with a 'nulled' $SDK
variable.
Does your current code not initialize the correct classes?
T
-----Original Message-----
From: Ian Barnes [mailto:ian@opteqint.net]
Sent: 08 September 2005 07:19 AM
To: jason.davidson@gmail.com
Cc: 'PHP General'
Subject: RE: [PHP] Help with Class
Hi,
Thanks for the help, but none of those worked.
Anyone else got any suggestions? Or possibly another way of achieving this ?
Cheers
Ian
_____
From: Jason Davidson [mailto:jason.davidson@gmail.com]
Sent: 07 September 2005 05:47 PM
To: Ian Barnes
Cc: PHP General
Subject: Re: [PHP] Help with Class
I would have guessed unset($sqk); to work, but also try $sdk = null;
Jason
On 9/7/05, Ian Barnes <ian@opteqint.net> wrote:
Hi,
I am writing a site where I need to access multiple classes of the same name
located under certain directories. The reason for each directory is because
the class under that directory talks only to the files in that directory and
cant do multiple (its not my software)
I have it so that I choose which ones I want to "post" to via checkboxes. I
then do a foreach loop and here it is:
foreach ( $forums as $num=>$val )
{
$db = new db ( 'localhost' , 'user' ,
'pass' , 'db' );
$sql = 'SELECT * FROM table WHERE id =
"'.$val.'"';
$result = $db->get($sql);
$fetchd = mysql_fetch_array ( $result );
$forumid = $fetchd['forumid'];
$posterid = $fetchd['posterid'];
$title = $_POST['title'];
$desc = $_POST['desc'];
$post = $_POST['post'];
require_once (
$fetchd['path'].'sdk/ipbsdk_class.inc.php' );
$SDK =& new ipbsdk;
$info = $SDK -> get_info ( $posterid );
$postername = $info['name'];
echo "Forum ID:".$forumid;
echo "<BR>Title:".$title;
echo "<BR>Desc:".$desc;
echo "<BR>Post:".$post;
echo "<BR>PosterID:".$posterid;
echo "<BR>PosterName:".$postername;
echo "<BR>";
}
See at the end of that foreach loop I need to unset the class $SDK so I can
re-init it from another dir. How can I do this? I have tried some of the
following:
Unset ( $SDK);
Unset ($GLOBALS['SDK'] );
Can anyone shed any light on my predicament ?
Thanks in advance
Cheers
Ian
--
PHP General Mailing List ( http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Navigation:
[Reply to this message]
|