<?php
//нихуя не работает, что делать с этим пока не знаю.
class Calc
{
public function createStack() {
$newStack = new Stack;
return $newStack;
}
public function sum() {
$augend = $this->pop();
$addend = $this->pop();
$this->push($augend+$addend);
}
}
//Вроде всё норм работает, пуш добавляет элемент в стек, поп извлекает.
class Stack
{
public $body = [];
public function push($a) {
$this->body[] = $a;
}
public function isEmpty() {
return (count($this->body)==0); }
public function pop() {
if (!$this->isEmpty()) {
return $poped;
} else {
return null;
}
}
}
//$test = new Stack;
//$test->push(2);
//$test->push(4);
//var_dump($test);
$test1 = new Calc;
$test1->createStack;
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKCi8v0L3QuNGF0YPRjyDQvdC1INGA0LDQsdC+0YLQsNC10YIsINGH0YLQviDQtNC10LvQsNGC0Ywg0YEg0Y3RgtC40Lwg0L/QvtC60LAg0L3QtSDQt9C90LDRji4KY2xhc3MgQ2FsYwp7CglwdWJsaWMgZnVuY3Rpb24gY3JlYXRlU3RhY2soKSB7CgkJJG5ld1N0YWNrID0gbmV3IFN0YWNrOwoJCXJldHVybiAkbmV3U3RhY2s7Cgl9CgkKCXB1YmxpYyBmdW5jdGlvbiBzdW0oKSB7CgkJJGF1Z2VuZCA9ICR0aGlzLT5wb3AoKTsKCQkkYWRkZW5kID0gJHRoaXMtPnBvcCgpOwoJCSR0aGlzLT5wdXNoKCRhdWdlbmQrJGFkZGVuZCk7CgkJCgl9Cn0KCi8v0JLRgNC+0LTQtSDQstGB0ZEg0L3QvtGA0Lwg0YDQsNCx0L7RgtCw0LXRgiwg0L/Rg9GIINC00L7QsdCw0LLQu9GP0LXRgiDRjdC70LXQvNC10L3RgiDQsiDRgdGC0LXQuiwg0L/QvtC/INC40LfQstC70LXQutCw0LXRgi4KY2xhc3MgU3RhY2sKewoJcHVibGljICRib2R5ID0gW107CgkKCXB1YmxpYyBmdW5jdGlvbiBwdXNoKCRhKSB7CgkJJHRoaXMtPmJvZHlbXSA9ICRhOwoJfQoKCXB1YmxpYyBm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