Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Break-OO-privacy/PHP/break-oo-privacy-1.php
Normal file
19
Task/Break-OO-privacy/PHP/break-oo-privacy-1.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
class SimpleClass {
|
||||
private $answer = "hello\"world\nforever :)";
|
||||
}
|
||||
|
||||
$class = new SimpleClass;
|
||||
ob_start();
|
||||
|
||||
// var_export() expects class to contain __set_state() method which would import
|
||||
// data from array. But let's ignore this and remove from result the method which
|
||||
// sets state and just leave data which can be used everywhere...
|
||||
var_export($class);
|
||||
$class_content = ob_get_clean();
|
||||
|
||||
$class_content = preg_replace('"^SimpleClass::__set_state\("', 'return ', $class_content);
|
||||
$class_content = preg_replace('"\)$"', ';', $class_content);
|
||||
|
||||
$new_class = eval($class_content);
|
||||
echo $new_class['answer'];
|
||||
8
Task/Break-OO-privacy/PHP/break-oo-privacy-2.php
Normal file
8
Task/Break-OO-privacy/PHP/break-oo-privacy-2.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
class SimpleClass {
|
||||
private $answer = 42;
|
||||
}
|
||||
|
||||
$class = new SimpleClass;
|
||||
$classvars = (array)$class;
|
||||
echo $classvars["\0SimpleClass\0answer"];
|
||||
12
Task/Break-OO-privacy/PHP/break-oo-privacy-3.php
Normal file
12
Task/Break-OO-privacy/PHP/break-oo-privacy-3.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
class fragile {
|
||||
private $foo = 'bar';
|
||||
}
|
||||
$fragile = new fragile;
|
||||
$ro = new ReflectionObject($fragile);
|
||||
$rp = $ro->getProperty('foo');
|
||||
$rp->setAccessible(true);
|
||||
var_dump($rp->getValue($fragile));
|
||||
$rp->setValue($fragile, 'haxxorz!');
|
||||
var_dump($rp->getValue($fragile));
|
||||
var_dump($fragile);
|
||||
Loading…
Add table
Add a link
Reference in a new issue