Class and object confusing - passing to function - value does not get passed.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi there,

I have a bit of confusion which I'm sure will be easily explained by the
experts here.

I'm implementing a class which had worked well for getting values from a DB
and representing them as an object. However, I however, I'm confused by
behavior when passing a object value to another class function as it's value
does not seem to get sent to the class function.

The class contains a public function which loads many values into a public
variable for the class. Therefore something like this:

class {

public $DBrowArray; // After a DB call is loaded with an array where each
table field can be access via $DBrowArray['tablefield']

public function getDBvaluesbyRowID($row_id) {
    #Do SQL stuff until we load an array from the

        DBrowArray = $DBres->fetchRow(DB_FETCHMODE_ASSOC);
        //Up to this part of the class I've used well for a while without

        #Now take on of the fields form the SQL result and explode it into
an array using a special function and make it publically available
        $this->DBrowArray['extra_array_value'] =


//Special function to explode a string.
private specialfunction($valueToWorkOn) {
    echo $valueToWorkOn; //Prints nothing
   //Yet if I try this below
    $this->DBrowArray['field_from_DB']); //This does print the value as

    //Even when I try this
    $valueToWorkOn = $this->DBrowArray['field_from_DB']);
    echo $valueToWorkOn; //Still Prints nothing

    $my_array = explode (",",$valueToWorkOn); //This returns nothing as
$valueToWorkOn is always empty
    return $my_array;


So my question is, how comes I cannot get $valueToWorkOn to contain the
value of   $this->DBrowArray['field_from_DB']).

I have just made a typo in my code (I've not shown my exact code for the
sake of brevity) or is the problem I'm presenting expected behavior

Thanks in advance.

Re: Class and object confusing - passing to function - value does not get passed. wrote:
Quoted text here. Click to load it

If the code is as you say, it should work.  There is a problem somewhere

I recommend you post your real code here, limiting it to the minimum
necessary to show the problem.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline