Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- SPL: ArrayObject::exchangeArray() basic usage with object as underlying data stor..

Decoded Output download

--TEST--
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
--FILE--
<?php

class C {
    public $pub1 = 'public1';
}

echo "--> exchangeArray() with objects:
";
$original = new C;
$ao = new ArrayObject($original);
$swapIn = new C;
try {
    $copy = $ao->exchangeArray($swapIn);
    $copy['addedToCopy'] = 'added To Copy';
} catch (Exception $e) {
    echo "Exception:" . $e->getMessage() . "
";
}
$swapIn->addedToSwapIn = 'added To Swap-In';
$original->addedToOriginal = 'added To Original';
var_dump($ao, $original, $swapIn, $copy);


echo "

--> exchangeArray() with no arg:
";
unset($original, $ao, $swapIn, $copy);
$original = new C;
$ao = new ArrayObject($original);
try {
    $copy = $ao->exchangeArray();
    $copy['addedToCopy'] = 'added To Copy';
} catch (TypeError $e) {
    echo "Exception: " . $e->getMessage() . "
";
}
$original->addedToOriginal = 'added To Original';
var_dump($ao, $original, $copy);

echo "

--> exchangeArray() with bad arg type:
";
unset($original, $ao, $swapIn, $copy);
$original = new C;
$ao = new ArrayObject($original);
try {
    $copy = $ao->exchangeArray(null);
    $copy['addedToCopy'] = 'added To Copy';
} catch (TypeError $e) {
    echo $e->getMessage() . "
";
}
$original->addedToOriginal = 'added To Original';
var_dump($ao, $original, $copy);

?>
--EXPECTF--
--> exchangeArray() with objects:
object(ArrayObject)#2 (1) {
  ["storage":"ArrayObject":private]=>
  object(C)#3 (2) {
    ["pub1"]=>
    string(7) "public1"
    ["addedToSwapIn"]=>
    string(16) "added To Swap-In"
  }
}
object(C)#1 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToOriginal"]=>
  string(17) "added To Original"
}
object(C)#3 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToSwapIn"]=>
  string(16) "added To Swap-In"
}
array(2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToCopy"]=>
  string(13) "added To Copy"
}


--> exchangeArray() with no arg:
Exception: ArrayObject::exchangeArray() expects exactly 1 argument, 0 given

Warning: Undefined variable $copy in %s on line %d
object(ArrayObject)#2 (1) {
  ["storage":"ArrayObject":private]=>
  object(C)#3 (2) {
    ["pub1"]=>
    string(7) "public1"
    ["addedToOriginal"]=>
    string(17) "added To Original"
  }
}
object(C)#3 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToOriginal"]=>
  string(17) "added To Original"
}
NULL


--> exchangeArray() with bad arg type:
ArrayObject::exchangeArray(): Argument #1 ($array) must be of type array, null given

Warning: Undefined variable $copy in %s on line %d
object(ArrayObject)#3 (1) {
  ["storage":"ArrayObject":private]=>
  object(C)#2 (2) {
    ["pub1"]=>
    string(7) "public1"
    ["addedToOriginal"]=>
    string(17) "added To Original"
  }
}
object(C)#2 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToOriginal"]=>
  string(17) "added To Original"
}
NULL

Did this file decode correctly?

Original Code

--TEST--
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
--FILE--
<?php

class C {
    public $pub1 = 'public1';
}

echo "--> exchangeArray() with objects:\n";
$original = new C;
$ao = new ArrayObject($original);
$swapIn = new C;
try {
    $copy = $ao->exchangeArray($swapIn);
    $copy['addedToCopy'] = 'added To Copy';
} catch (Exception $e) {
    echo "Exception:" . $e->getMessage() . "\n";
}
$swapIn->addedToSwapIn = 'added To Swap-In';
$original->addedToOriginal = 'added To Original';
var_dump($ao, $original, $swapIn, $copy);


echo "\n\n--> exchangeArray() with no arg:\n";
unset($original, $ao, $swapIn, $copy);
$original = new C;
$ao = new ArrayObject($original);
try {
    $copy = $ao->exchangeArray();
    $copy['addedToCopy'] = 'added To Copy';
} catch (TypeError $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
$original->addedToOriginal = 'added To Original';
var_dump($ao, $original, $copy);

echo "\n\n--> exchangeArray() with bad arg type:\n";
unset($original, $ao, $swapIn, $copy);
$original = new C;
$ao = new ArrayObject($original);
try {
    $copy = $ao->exchangeArray(null);
    $copy['addedToCopy'] = 'added To Copy';
} catch (TypeError $e) {
    echo $e->getMessage() . "\n";
}
$original->addedToOriginal = 'added To Original';
var_dump($ao, $original, $copy);

?>
--EXPECTF--
--> exchangeArray() with objects:
object(ArrayObject)#2 (1) {
  ["storage":"ArrayObject":private]=>
  object(C)#3 (2) {
    ["pub1"]=>
    string(7) "public1"
    ["addedToSwapIn"]=>
    string(16) "added To Swap-In"
  }
}
object(C)#1 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToOriginal"]=>
  string(17) "added To Original"
}
object(C)#3 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToSwapIn"]=>
  string(16) "added To Swap-In"
}
array(2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToCopy"]=>
  string(13) "added To Copy"
}


--> exchangeArray() with no arg:
Exception: ArrayObject::exchangeArray() expects exactly 1 argument, 0 given

Warning: Undefined variable $copy in %s on line %d
object(ArrayObject)#2 (1) {
  ["storage":"ArrayObject":private]=>
  object(C)#3 (2) {
    ["pub1"]=>
    string(7) "public1"
    ["addedToOriginal"]=>
    string(17) "added To Original"
  }
}
object(C)#3 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToOriginal"]=>
  string(17) "added To Original"
}
NULL


--> exchangeArray() with bad arg type:
ArrayObject::exchangeArray(): Argument #1 ($array) must be of type array, null given

Warning: Undefined variable $copy in %s on line %d
object(ArrayObject)#3 (1) {
  ["storage":"ArrayObject":private]=>
  object(C)#2 (2) {
    ["pub1"]=>
    string(7) "public1"
    ["addedToOriginal"]=>
    string(17) "added To Original"
  }
}
object(C)#2 (2) {
  ["pub1"]=>
  string(7) "public1"
  ["addedToOriginal"]=>
  string(17) "added To Original"
}
NULL

Function Calls

None

Variables

None

Stats

MD5 302b74f9a4cf91d0ad155df43f2cbda0
Eval Count 0
Decode Time 97 ms