Skip to content

Instantly share code, notes, and snippets.

@gadiener
Forked from lastguest/test.tree.php
Created May 22, 2017 07:35
Show Gist options
  • Save gadiener/380477cb205aa151e8d02d61fe4a4373 to your computer and use it in GitHub Desktop.
Save gadiener/380477cb205aa151e8d02d61fe4a4373 to your computer and use it in GitHub Desktop.
[CAFFEINA] Exercise #1
<?php
include "tree.php";
$x = new Tree();
$x->bacon = "Pancetta";
$x->pasta["fagioli"] = 3;
$y = clone $x;
$y->pasta = null;
$y->pasta->fagioli = [1];
$y->alpha->beta->gamma = "Carote";
var_dump($x,$y);
echo "\n$x\n$y";
<?php
/**
* Develop the class responsibile for the provided output in file : video.output.txt
*/
class Tree {}
object(Tree)#1 (2) {
["bacon"]=>
string(8) "Pancetta"
["pasta"]=>
object(Tree)#2 (1) {
["fagioli"]=>
int(3)
}
}
object(Tree)#3 (3) {
["bacon"]=>
string(8) "Pancetta"
["pasta"]=>
object(Tree)#4 (1) {
["fagioli"]=>
array(1) {
[0]=>
int(1)
}
}
["alpha"]=>
object(Tree)#5 (1) {
["beta"]=>
object(Tree)#6 (1) {
["gamma"]=>
string(6) "Carote"
}
}
}
{"bacon":"Pancetta","pasta":{"fagioli":3}}
{"bacon":"Pancetta","pasta":{"fagioli":[1]},"alpha":{"beta":{"gamma":"Carote"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment