Page 1 of 1

PHP4 class nesting depth

Posted: Thu Jan 22, 2004 12:49 pm
by Zher
I've run into a problem and cannot figure it out for the life of me... :evil:

Basically I have a class within a class, and so on...

I have a method that Populates a floorplan floor with Elements in that floor. If I dump $workorder->floorplan->floor->elements (outside of the Populate call) it is blank, however... dumping immediatly after my PopulateFloor call does it's thing (inside the actual function though) shows the correct information.

There is nothing different about the printout outside of the Populate call besides that it's outside the function hehe. I just can't seem to figure this one out...

workorder is a WorkOrder object
floorplan is a FloorPlan object
floor is an array of Floor objects
elements is an array of FloorElement objects.

Any help would be... helpful hehe.

Thanks,
Zher

Re: PHP4 class nesting depth

Posted: Thu Jan 22, 2004 1:50 pm
by jaxn
Zher wrote: If I dump $workorder->floorplan->floor->elements (outside of the Populate call) it is blank, however... dumping immediatly after my PopulateFloor call does it's thing (inside the actual function though) shows the correct information.
Is $workorder global? If not then you need to make $workorder a property of one of your classes so that you can access it inside that class's namespace.

Though I could be completly misunderstanding your problem. More code would help me out.

-Jackson

Posted: Thu Jan 22, 2004 2:04 pm
by Zher

Code: Select all

<?php

$wo['sql'] = "SELECT * FROM work_order WHERE work_order_id = '" . $_GET['work_order_id'] . "'";
$wo['result'] = mysql_query($wo['sql'], $_SESSION['db']) or die("Error  " . mysql_error());
$woInfo = mysql_fetch_object($wo['result']);

print "<pre>";
$woInfo->user_id = $_SESSION['user_id'];

$WorkOrder = new WorkOrder($woInfo);
$WorkOrder->PopulateWorkOrder();
echo "<br>";
print_r($WorkOrder);
?>
I know Session variable for db probably isn't the best of ideas egh. Not great code but the print_r on $WorkOrder is showing nothing. I'm fairly sure it's not a global issue.

Thanks,
Zher

Posted: Thu Jan 22, 2004 5:13 pm
by Zher
Figured it out, here's the unfixed offending code heh.

Code: Select all

<?php
		function PopulateFloorPlan($workOrderID) {
			if ($this->floors) {
				foreach($this->floors as $floor) {
					$floor->PopulateFloor($workOrderID);
				}
			} else {
				return 0;
			}
		}
?>
And the fix, I get why it does it but it is just dumb.

Code: Select all

<?php
		function PopulateFloorPlan($workOrderID) {
			if ($this->floors) {
				foreach($this->floors as $key=>$floor) {
					$floor->PopulateFloor($workOrderID);
					$this->floors[$key] = $floor;
				}
			} else {
				return 0;
			}
		}
?>