Page 1 of 1

[SOLVED] PHP Class __construct Problem

Posted: Wed Mar 23, 2005 12:41 pm
by varlanta
I'm quite new to PHP, and I'm having issues creating a class.

The class has 6 private member variables:

1. Shop Order
2. Customer
3. Part ID
4. Pieces
5. Bins
6. Loads

Basically, I'm using the shop order number to look up the other 5 fields in a database stored on an IBM iSeries (where shop order number is the primary key for the table). The database operations are no problem (using Windows 2000 and a System DSN, I can easily connect and query through ODBC).

The problem I'm having, though, is that when I assign a value to shop order, for example, in my constructor (which requires the shop order be given), it assigns the same value to customer, part id, pieces, bins, and loads. Then, if I try to assign a different value to customer, it assigns the value to all six fields. I must be doing something wrong, but can't for the life of me figure out what.

Here's my class code:

Code: Select all

<?php
	/***********************************
	* definition of class VMSShopOrder *
	***********************************/
	class VMSShopOrder
	{
		//private members
		//---------------
		private $shopOrder = "";    //shop order number (given by user)
		private $customer = "";     //customer code (from iSeries -> shopOrder)
		private $partId = "";       //part id (from iSeries -> shopOrder)
		private $pieces = 0;        //# pieces (from iSeries -> shopOrder)
		private $bins = 0;          //# bins (from iSeries -> shopOrder)
		private $loads = 0;         //# loads (from iSeries -> shopOrder)
		
		/***********************
		* Default constructor. *
		***********************/
		function __construct($initShopOrder)
		{		
			//as long as object defined
			if (isset($this))
			{
				print("Shop order: " . $this->$shopOrder . "<br>");
				print("Customer: " . $this->$customer . "<br>");
			
				//set the shop order to the passed value
				$this->$shopOrder = $initShopOrder;
				
				print("Shop order: " . $this->$shopOrder . "<br>");
				print("Customer: " . $this->$customer . "<br>");
				
				//the rest of the constructor goes here
			}
		}
	}
?>
Assume I pass shop order number "123456" to the constructor. Here's what I get:

Code: Select all

Shop order:
Customer:
Shop order: 123456
Customer 123456
I obviously go on to do other things in the class, but this is a real stumbling block for me. Any help would be greatly appreciated.

Posted: Wed Mar 23, 2005 1:23 pm
by feyd

Code: Select all

$this-&gt;shopOrder;

[SOLVED] That did it.

Posted: Wed Mar 23, 2005 1:44 pm
by varlanta
I thought I was probably doing something stupid, and that was the case. Thanks for the quick help.