Jump to content

Instantiating and full URLs...


Aureole

Recommended Posts

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 ....

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.