rubing Posted May 24, 2008 Share Posted May 24, 2008 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 More sharing options...
minidak03 Posted May 24, 2008 Share Posted May 24, 2008 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 https://forums.phpfreaks.com/topic/107026-object-needs-external-libs/#findComment-548713 Share on other sites More sharing options...
bilis_money Posted May 24, 2008 Share Posted May 24, 2008 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 https://forums.phpfreaks.com/topic/107026-object-needs-external-libs/#findComment-548727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.