Jump to content

object needs external libs


rubing

Recommended Posts

I am writing oop code for the first time. even though i've read a lot about it i'm having troubles. here's two things maybe you guys can help me out on, I hope.

 

1.  What if my class requires external libraries?

 

I have never seen this done.  Am I supposed to include them in my script before calling a new object instance?

 

2.  Can I have a member array?  Are they assigned like variables?  (e.g. static var $lawsuit;)

 

 

Thanks!

Link to comment
Share on other sites

You would do something like this

 

include_once('external_library');

class myClass {
    function myClassFun() {
        // now to use the outside function you can do this
        $class = new externalClass(); // assuming this is the name of the external class
        $something = $class->whatever();
    }
}

 

Please not in the little example above the var $class is only accessable inside of the function myClassFun.

Link to comment
Share on other sites

a good habit is always create the object after you are done declaring the class for example,

 

auto.php

<?php
class auto {
    function auto() {
        // more code here...
    }

}
    $auto = new auto(); //always instantiate the object after the class declaration
?>

 

 

ship.php

<?php
include ('auto.php');

class ship {
    function ship() {
        // more code here...
    }
}

    $ship = new ship(); //always instantiate the object after the class declaration
?>

 

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.