Can I initiate a class from within a method of a seperate class
For example, below is a class called Detect that has an attribute called $oBudDb, which I'd hoped to use in further methods within the Detect class. This attribute is assigned to another class seperate to Detect.
This other class, Remote_ibisdb1_MsSQL(), extends a Class DB_MsSQL().
However, when I debug this on ZDE a debug error is displayed:
Debug Error: ..\Class DB_MsSQL.inc line 116 - Call to undefined function: mssql_connect()
Can anyone help?
Might it be that an extended class cannot be called from within another class?
$user = new Detect( $_SESSION["ibis_username"] );
....
....
class Detect {
var $oBudDb; // database handling class
var $found;
var $loginID; // UserID
var $shtName; // USerName
var $fstName; // Firstname
var $LstName; // Surname
var $usrDept; // UserDept
var $scopeID; // UserAccess
var $depCode; // DeptCode
var $depDesc; // DeptDesc
var $depHldr; // BudHldr
var $depMngr; // LineMgr
var $ibisRef; // ibis_name
function Detect( $ibisRef ){
if( !class_exists( $oBudDb ) ) $oBudDb = new Remote_ibisdb1_MsSQL(); // Extension of DB_MsSQL with connects to a server and selects the database
$oBudDb->Query( "SELECT UserID, UserName, Surname, Firstname, UserDept, UserAccess ".
"FROM BudgetReport ".
"WHERE UserID = '".$_SESSION["ibis_username"]."' ".
"AND UserAccess IS NOT NULL ".
"GROUP BY UserID, UserName, Surname, Firstname, UserDept, UserAccess " );
The above line and this one have worked in similar circumstances but zend debugger seems to have a problem.
instantiating a class within a method of a seperate class
Moderator: General Moderators
I think you may be missunderstanding the concepts of OO a little bit, a class is just a definition, or structure.. An Object is an instance of a class, nothing inside a class is "alive" until it is instatinated.. However, it is possible to call methods in a class, however, this method will not have any data from itself.. class_exist() s will check if the class has been defined, not if there has been any objects instatinated from that class.
Using OO in PHP is not very efficient, not recommended for high-volume sites unless you need a lot of dynamical behaviour, building data trees and such.. If you find yourself using globals and such, the whole point of OO is lost..
here is a simple and silly sample of (untested) a class inheritance and an object holding other objects..
Using OO in PHP is not very efficient, not recommended for high-volume sites unless you need a lot of dynamical behaviour, building data trees and such.. If you find yourself using globals and such, the whole point of OO is lost..
here is a simple and silly sample of (untested) a class inheritance and an object holding other objects..
Code: Select all
<?php
class beverage {
var $level;
var $brand;
var $type;
function buy () {
$this->level++;
}
function drink () {
if ($this->level) $this->level--;
else return 'None left';
}
}
class beer extends beverage {
function beer ($brand) {
$this->type = 'beer';
$this->brand = $brand;
}
}
class party {
var $beverage;
function buy_beer ($amount,$brand) {
$this->beverage['beer'][$brand] = new beer($brand);
while ($amount--) $this->beverage['beer'][$brand]->buy();
}
function drink_beer ($brand) {
if (is_object($this->beverage['beer'][$brand])) {
return $this->beverage['beer'][$brand]->drink());
}
}
}
$spring_break = new party;
$spring_break->buy_beer(24,'Sam Adams'); # Just as if $spring_break->beverage['beer']['Sam Adams']->level == 24
$spring_break->drink_beer('Sam Adams');
?>