Two Child Arrays Within One Parent Array Problem: one child array is processed after processing both child arrays have same result

Viewed 63

I have an array for the page to handle data within shown below:

(B4:CCTB SPEC FIX) $FIXER_INPUTS reads:

stdClass Object
(
    [CCTB] => stdClass Object
        (
            [OLD] => 90-15-6170
            [NEW] => 90-15-6170
            [OLD_SPEC] => stdClass Object
                (
                    [volt] => 12 Volt
                    [series] => K1 Series
                    [amp] => 65
                )
            [NEW_SPEC] => stdClass Object
                (
                    [volt] => 12 Volt
                    [series] => K1 Series
                    [amp] => 65
                )
        )
    [SPECS] => stdClass Object
        (
            [OLD] => stdClass Object
                (
                    [series] => K2
                    [volt] => 24
                    [amp] => 0
                    [rotation] => NO
                    [teeth] => 75
                    [splines] => 0
                    [kw] => 0.00
                    [o_d] => 1.625
                )
            [NEW] => 
            [OLD_TYPE] => 90
        )
)

I then pass specific groups to the processing page to remove letters and correct data mis-alignment issues. And data passed is shown below:

$CSF['spec_type'] = $FIXER_INPUTS->SPECS->OLD_TYPE;
$CSF['part_specs'] = $FIXER_INPUTS->SPECS->OLD;
$CSF['cctb_specs'] = $FIXER_INPUTS->CCTB->OLD_SPEC;
include("cctb_spec_fixer.php");/* processing page */
$FIXER_INPUTS->SPECS->OLD = $CSF['part_specs'];
$FIXER_INPUTS->CCTB->OLD_SPEC = $CSF['cctb_specs'];

And the array for the processing page is shown below:

(cctb_spec_fixer)initial)$CSF reads:

Array
(
    [spec_type] => 90
    [part_specs] => stdClass Object
        (
            [series] => K2
            [volt] => 24
            [amp] => 0
            [rotation] => NO
            [teeth] => 75
            [splines] => 0
            [kw] => 0.00
            [o_d] => 1.625
        )
    [cctb_specs] => stdClass Object
        (
            [volt] => 12 Volt
            [series] => K1 Series
            [amp] => 65
        )
)

After processing the returned result is shown below:

(cctb_spec_fixer)final) $CSF reads:

Array
(
    [spec_type] => 90
    [part_specs] => stdClass Object
        (
            [series] => K1
            [volt] => 12
            [amp] => 65
            [rotation] => NO
            [teeth] => 0
            [splines] => 0
            [kw] => 0
            [o_d] => 1.625
        )
    [cctb_specs] => stdClass Object
        (
            [volt] => 12
            [series] => K1
            [amp] => 65
        )
)

So far so good then when the page array is printed out for verification, I get this:

(AF:CCTB SPEC FIX)$FIXER_INPUTS reads:

stdClass Object
(
    [CCTB] => stdClass Object
        (
            [OLD] => 90-15-6170
            [NEW] => 90-15-6170
            [OLD_SPEC] => stdClass Object
                (
                    [volt] => 12
                    [series] => K1
                    [amp] => 65
                )
            [NEW_SPEC] => stdClass Object
                (
                    [volt] => 12
                    [series] => K1
                    [amp] => 65
                )
        )
    [SPECS] => stdClass Object
        (
            [OLD] => stdClass Object
                (
                    [series] => K1
                    [volt] => 12
                    [amp] => 65
                    [rotation] => NO
                    [teeth] => 0
                    [splines] => 0
                    [kw] => 0
                    [o_d] => 1.625
                )
            [NEW] => 
            [OLD_TYPE] => 90
        )
)

As you can see both $FIXER_INPUTS->CCTB->OLD_SPEC and $FIXER_INPUTS->CCTB->NEW_SPEC are identical even though only one ($FIXER_INPUTS->CCTB->OLD_SPEC) was passed to the processing page.

Why did that happened? Does it have to do with my array structure? Does PHP lose its mind with similar array keys at similar levels?

UPDATE: Since I used the following to get the data for both $FIXER_INPUTS->CCTB->OLD_SPEC and $FIXER_INPUTS->CCTB->NEW_SPEC:

$CCTB_SPEC_DATA = getChainSpecLIST($FIXER_INPUTS->CCTB->OLD, $dbc);

here is the code for 'getChainSpecLIST':

function getChainSpecLIST($CHAIN, $dbc){
    // need both chain and type data
    if($CHAIN){
        global $SPEC_LIST_OLD;
        $sql = "SELECT ".$SPEC_LIST_OLD[substr($CHAIN,0,2)]." FROM product_specs WHERE wil_no = \"".$CHAIN."\"";
        $res = sql_query($sql, $dbc);
        $num = mysqli_num_rows($res);
        if($num > 0){
            $row = mysqli_fetch_assoc($res);
            $DATA_RETURN = (object) $row;
            return (object)$DATA_RETURN;
        }else{
            return false;
        }
    }else{
        return false;
    }
}

$SPEC_LIST_OLD reads as follows:

$SPEC_LIST_OLD['90'] = 'volt, series, amp';
$SPEC_LIST_OLD['91'] = 'volt, rotation, series, kw, teeth';
$SPEC_LIST_OLD['92'] = 'volt, rotation, series, kw, splines';
$SPEC_LIST_OLD['94'] = 'volt, rotation, series, kw, splines';

Then I transfer the data to the page array ($FIXER_INPUTS):

$FIXER_INPUTS->CCTB->OLD_SPEC = $CCTB_SPEC_DATA;
$FIXER_INPUTS->CCTB->NEW_SPEC = $CCTB_SPEC_DATA;

Then I use the UNSET to destroy the $CCTB_SPEC_DATA data:

unset($CCTB_SPEC_DATA);

This is how I got the issue above. But I did some testing and I got a different result, which makes me wonder about UNSET function in the scheme of things. Does it truly remove the variable being unset or just clears values. To be truly UNSET means no trace of it to found throughout the page action after the variable is UNSET-ted.

This leads me to my findings:

I tried to test the building of data for $FIXER_INPUTS->CCTB->NEW_SPEC, to find at which degree when the above issue arises. First, I tried setting the $FIXER_INPUTS->CCTB->NEW_SPEC to no child entries. NO ISSUE AS SEEN ABOVE Second, I tried setting individual child entries to blank data. NO ISSUE AS SEEN ABOVE Third, I tried setting individual child entries with data. NO ISSUE AS SEEN ABOVE Fourth, I re-wrote the code for filling the array as shown below:

$FIXER_INPUTS->CCTB->OLD_SPEC = getChainSpecLIST($FIXER_INPUTS->CCTB->OLD, $dbc);
$FIXER_INPUTS->CCTB->NEW_SPEC = getChainSpecLIST($FIXER_INPUTS->CCTB->OLD, $dbc);

I called the function(this application isn't built in OOP style with Classes) on each child separately and the end result was NO ISSUE AS SEEN ABOVE as seen in the array below:

(AF:CCTB SPEC FIX)$FIXER_INPUTS reads:

stdClass Object
(
    [CCTB] => stdClass Object
        (
            [OLD] => 90-15-6170
            [NEW] => 90-15-6170 
            [OLD_SPEC] => stdClass Object
                (
                    [volt] => 12
                    [series] => K1
                    [amp] => 65
                )
            [NEW_SPEC] => stdClass Object
                (
                    [volt] => 12 Volt
                    [series] => K1 Series
                    [amp] => 65
                )
        )
    [SPECS] => stdClass Object
        (
            [OLD] => stdClass Object
                (
                    [series] => K1
                    [volt] => 12
                    [amp] => 65
                    [rotation] => NO
                    [o_d] => 1.625
                )
            [NEW] => 
            [OLD_TYPE] => 90
        )
)

So now the real question is "why does UNSET truly not clear all traces of said variable from memory?" Some how calling a function once to get data (assigned to a single tmp-variable for passing along) and applying that data to two separate child arrays then UNSET-ting that tmp-variable truly doesn't UNSET the tmp-variable and all traces of said tmp-variable after UNSET is used.

0 Answers
Related