Aureole Posted October 12, 2007 Share Posted October 12, 2007 Why does instantiating not work when I give a full URL to the class... e.g. http://www.domain.com/dir/file.php Quote Link to comment Share on other sites More sharing options...
trq Posted October 12, 2007 Share Posted October 12, 2007 Post the relevent code. But in short, classes don't just instatiate themselves when included. Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 12, 2007 Author Share Posted October 12, 2007 Sorry didn't think it was needed... <?php <?php session_start(); require_once('http://www.starwarsrevolution.net/classes/class_database.swr3'); $swr3->database = new database; $swr3->database->connect(); $database->output->connect = $swr3->database->output; echo $database->output->connect; ?> I also get the error when I tried to require the class from a different website... The error is something like "Cannot instantiate non existant class on line 5 of .... Quote Link to comment Share on other sites More sharing options...
trq Posted October 12, 2007 Share Posted October 12, 2007 Most servers do not allow files to be included via a url. To enable it you will need to enable allow_url_fopen and allow_url_include in your php.ini then restart your server. Be aware though that most hosts do not support this feature. Best bet is to use relative or full paths to included files. PS: This really has nothing to do with OOP. Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 12, 2007 Author Share Posted October 12, 2007 Well I thought it was to do with OOP as the afore-mentioned error said cannot instantiate class... and classes are to do with OOP. Thanks anyway. When you say relative I know what you mean but what do you mean when you say full paths? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 12, 2007 Share Posted October 12, 2007 where is the code for your database class included? i see the swr3 but if that is child class then you'll need the parent too. Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 12, 2007 Author Share Posted October 12, 2007 It's not a child class just instead of doing like: $database = new database; I did: $swr3->database = new database; Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 12, 2007 Share Posted October 12, 2007 so in class_database.swr3 you have $swr3 = new OBJECT; along with the code for that object? Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 12, 2007 Author Share Posted October 12, 2007 Nope I just wanted to have $swr3-> before it, it still works so I don't see the problem... Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 12, 2007 Share Posted October 12, 2007 well $swr3->database = new database means you have a class $swr3 and you are creating another class (called database) inside it... so if you don't hvae the code for withe class then it will fail. Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 13, 2007 Author Share Posted October 13, 2007 Well there isn't any code for a class of swr3 and it works fine. ??? So... Quote Link to comment Share on other sites More sharing options...
trq Posted October 13, 2007 Share Posted October 13, 2007 Nope I just wanted to have $swr3-> before it, it still works so I don't see the problem... The problem is youve made a new class $swr3 of the type StdClass for no reason. It also makes your code a little harder to follow because people will be looking for where you instantiate this $swr3 object. What on earth would you want to have an extra $swr3-> infront of all calls to your object? It smakes no sense, and is a habbit you should avoid. As for full paths. A full path is exactly that. The full path to your file from the root (/) directory. eg; /home/thorpe/foo/bar.php Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 13, 2007 Author Share Posted October 13, 2007 Well eventually there would be a class for $swr3 but right now I don't have a need for it and I don't really know how to make it so that $swr3 is the parent class and the others are "sub classes". I searched for Hours on how to do the as you say StdClass and couldn't find anything, I guess I was searching for the wrong things... Quote Link to comment Share on other sites More sharing options...
trq Posted October 13, 2007 Share Posted October 13, 2007 Well eventually there would be a class for $swr3 but right now I don't have a need for it and I don't really know how to make it so that $swr3 is the parent class and the others are "sub classes". That is called extending and has nothing to do with referencing classes by $parent->child->method syntax. I searched for Hours on how to do the as you say StdClass and couldn't find anything Simply by using the $class->foo syntax automatically creates an object of type stdClass. An example.... <?php $class->foo = 'bar'; print_r($class); ?> Quote Link to comment Share on other sites More sharing options...
Aureole Posted October 13, 2007 Author Share Posted October 13, 2007 Ok, thanks a lot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.