<?php
$someBuffer = new Buffer();
$someBuffer('a string');
$someBuffer(array('an array'));
$otherBuffer = new Buffer();
$otherBuffer('another string');
echo "\nПочему \$otherBuffer скопировало \$someBuffer ?!! Это же разные инстансы.";
class Buffer
{
protected static
$stock = array();
public function clear() {
}
public function __invoke
($resource = array(), $key = false) { if ($key) {
self::$stock[$key] = $resource;
} else {
self::$stock[] = $resource;
}
}
public function release() {
return self::$stock;
}
}
PD9waHAKJHNvbWVCdWZmZXIgPSBuZXcgQnVmZmVyKCk7CiRzb21lQnVmZmVyKCdhIHN0cmluZycpOwokc29tZUJ1ZmZlcihhcnJheSgnYW4gYXJyYXknKSk7Cgokb3RoZXJCdWZmZXIgPSBuZXcgQnVmZmVyKCk7CiRvdGhlckJ1ZmZlcignYW5vdGhlciBzdHJpbmcnKTsKCnByaW50IGpzb25fZW5jb2RlKCRvdGhlckJ1ZmZlci0+cmVsZWFzZSgpKS4iXG4iOwoKZWNobyAiXG7Qn9C+0YfQtdC80YMgXCRvdGhlckJ1ZmZlciDRgdC60L7Qv9C40YDQvtCy0LDQu9C+IFwkc29tZUJ1ZmZlciA/ISEg0K3RgtC+INC20LUg0YDQsNC30L3Ri9C1INC40L3RgdGC0LDQvdGB0YsuIjsKCmNsYXNzIEJ1ZmZlcgp7CiAgcHJvdGVjdGVkIHN0YXRpYyAkc3RvY2sgPSBhcnJheSgpOwogIAogIHB1YmxpYyBmdW5jdGlvbiBjbGVhcigpIHsKICAgIHNlbGY6OiRzdG9jayA9IGFycmF5KCk7CiAgfQogIAogIHB1YmxpYyBmdW5jdGlvbiBfX2ludm9rZSgkcmVzb3VyY2UgPSBhcnJheSgpLCAka2V5ID0gZmFsc2UpIHsKICAgIGlmICgka2V5KSB7CiAgICAgIHNlbGY6OiRzdG9ja1ska2V5XSA9ICRyZXNvdXJjZTsKICAgIH0gZWxzZSB7CiAgICAgIHNlbGY6OiRzdG9ja1tdID0gJHJlc291cmNlOwogICAgfQogIH0KICAKICBwdWJsaWMgZnVuY3Rpb24gcmVsZWFzZSgpIHsKICAgIHJldHVybiBzZWxmOjokc3RvY2s7CiAgfQp9