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
https://forums.phpfreaks.com/topic/107026-object-needs-external-libs/
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.

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

 

Archived

This topic is now archived and is closed to further replies.

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