PHP4 class nesting depth

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zher
Forum Newbie
Posts: 3
Joined: Thu Jan 22, 2004 12:49 pm

PHP4 class nesting depth

Post 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
jaxn
Forum Commoner
Posts: 55
Joined: Fri Jan 16, 2004 1:50 pm
Location: Nashville, TN

Re: PHP4 class nesting depth

Post 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
Zher
Forum Newbie
Posts: 3
Joined: Thu Jan 22, 2004 12:49 pm

Post 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
Zher
Forum Newbie
Posts: 3
Joined: Thu Jan 22, 2004 12:49 pm

Post 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;
			}
		}
?>
Post Reply