passing Class to function
Posted: Fri Oct 16, 2009 11:45 am
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I have created a class called "Material" which is a collection of several properties.
Once I have imported all the data I might have 30 instances of Material.
One of the properties that I import is a date which can come in two formats: MM-DD-YY or YY-MM-DD
I have create the code to manipulate the date structure so that they all are formated the same however I have not tested it as I am not sure how to pass the information to the function/method. Also not sure but I think this is a case where the function/Method can be part of the class if I am not mistaken.
All dates need to be looked at once as I am looking for variances in the dates to help detemine which format the data is in.
In the main code I had started with: $material->check_date(); but got the resulting error.
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I have created a class called "Material" which is a collection of several properties.
Once I have imported all the data I might have 30 instances of Material.
One of the properties that I import is a date which can come in two formats: MM-DD-YY or YY-MM-DD
I have create the code to manipulate the date structure so that they all are formated the same however I have not tested it as I am not sure how to pass the information to the function/method. Also not sure but I think this is a case where the function/Method can be part of the class if I am not mistaken.
All dates need to be looked at once as I am looking for variances in the dates to help detemine which format the data is in.
In the main code I had started with: $material->check_date(); but got the resulting error.
Fatal error: Call to a member function check_date() on a non-object in D:\Documents and Settings\414004425\My Documents\My Websites\PETdb\md4c11.php on line 144
Code: Select all
class Material {
public $level; //Part level
public $part; //Part number
public $part_desc; //Part description
public $status; //Status of part
public $edate; //Date the parts are expected
public $rdate; //Date the parts are required by
public $qty; //Required quantity for project
public $pr; //Purchase requistion number to buy part
public $po; //PO numbere that is buying the part
public $line; //Line on PO that is purchasing the part
public $factory; //Manufacturing facility for part
public $error; //SAP error code
public $prod; //Production order number
function check_date() {
$d0=0;
$d1=0;
$d2=0;
for ($cnt=0; $count <= sizeof($this); ++$cnt) {
if (!is_null($this[$cnt]->rdate)) {
$date_a = explode("/",$this[$cnt]->rdate);
if ($d0 > $date_a[0]) {
$d0 = $date_a[0];
}
if ($d1 > $date_a[1]) {
$d1 = $date_a[1];
}
if ($d2 > $date_a[2]) {
$d2 = $date_a[2];
}
}
}
if ($d2 > 12) {
for ($cnt=0; $count <= sizeof($this[$cnt]->rdate); ++$cnt) {
if (!is_null($this[$cnt]->rdate)) {
$date_a = explode("/",$this[$cnt]->rdate);
$this[$cnt]->rdate = $date_a[1]."/".$date_a[2]."/".$date_a[0];
$date_a = explode("/",$this[$cnt]->edate);
$this[$cnt]->edate = $date_a[1]."/".$date_a[2]."/".$date_a[0];
}
}
}
}
function __construct() {
$this->level = NULL;
$this->part = NULL;
$this->part_desc = NULL;
$this->status = "SubcStock";
$this->edate = NULL;
$this->rdate = NULL;
$this->qty = NULL;
$this->pr = NULL;
$this->po = NULL;
$this->line = NULL;
$this->factory = NULL;
$this->error = NULL;
$this->prod = NULL;
}
}pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: