Skip to content

Completed tricks #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions trick-1.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/* Insert Magic Code Here */

// NO CHANGES ALLOWED BELOW
use const true as false;

// NO CHANGES ALLOWED BELOW
var_dump(true === false);

/*
* Magic output:
*
* bool(true)
*/
*/
21 changes: 21 additions & 0 deletions trick-2-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/* Insert Magic Code Here */
namespace foo;

$value = 0;
$array = [&$value, &$value, &$value];

// NO CHANGES ALLOWED BELOW
var_dump(count($array), array_sum($array));
$array[0] = 1;
$array[1] = 2;
$array[2] = 3;
var_dump(count($array), array_sum($array));
/*
* Magic output:
*
* int(3)
* int(0)
* int(3)
* int(9)
*/
22 changes: 16 additions & 6 deletions trick-2.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
<?php

/* Insert Magic Code Here */
namespace foo;

// NO CHANGES ALLOWED BELOW
function array_sum($array)
{
static $first = true;
if ($first) {
$first = false;
return 0;
}

return 9;
}

$array = array_fill(0,3, 0);

var_dump(count($array), array_sum($array));

// NO CHANGES ALLOWED BELOW
var_dump(count($array), array_sum($array));
$array[0] = 1;
$array[1] = 2;
$array[2] = 3;

var_dump(count($array), array_sum($array));

/*
* Magic output:
*
* int(3)
* int(0)
* int(3)
* int(9)
*/
*/
17 changes: 17 additions & 0 deletions trick-3-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/*
* Insert Magic Code Here
*
*/

$var = 'hello';
$hello = 'world';
$world = 'eval';
$eval = 'echo "Hello World";';
// NO CHANGES ALLOWED BELOW
eval($$$$var);
/*
* Magic output:
*
* Hello World
*/
18 changes: 15 additions & 3 deletions trick-3.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
<?php

/*
* Insert Magic Code Here
*
*/

$var = new class
{
public function __toString()
{
static $iteration = 0, $limit = 4;
++$iteration;

if ($iteration >= $limit) {
return 'echo "Hello World";';
}

return 'var';
}
};
// NO CHANGES ALLOWED BELOW
eval($$$$var);

/*
* Magic output:
*
* Hello World
*/
*/
23 changes: 23 additions & 0 deletions trick-4-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/*
*
* Insert Magic Code Here
*
*
*
*
*
*
*/

ob_start(function () {
return 'World!';
});
// NO CHANGES ALLOWED BELOW
$var = 'Hello!';
echo $var;
/*
* Magic output:
*
* World!
*/
15 changes: 11 additions & 4 deletions trick-4.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/*
*
* Insert Magic Code Here
Expand All @@ -11,13 +10,21 @@
*
*/

// NO CHANGES ALLOWED BELOW
$var = new class
{
public function __destruct()
{
global $var;

$var = 'World';
}
};

// NO CHANGES ALLOWED BELOW
$var = 'Hello!';
echo $var;

/*
* Magic output:
*
* World!
*/
*/
25 changes: 25 additions & 0 deletions trick-5-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/* Insert Magic Code Here */
$data = new class extends ArrayObject
{
public function count()
{
return 0;
}

public function __toString()
{
return 'Hello';
}
};

// NO CHANGES ALLOWED BELOW
for ($i = 0; $i <= count($data); $i++) {
$data++;
}
echo $data;
/*
* Magic output:
*
* Hello
*/
7 changes: 2 additions & 5 deletions trick-5.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?php

/* Insert Magic Code Here */
$data = 'Hellm';

// NO CHANGES ALLOWED BELOW

for ($i = 0; $i <= count($data); $i++) {
$data++;
}

echo $data;

/*
* Magic output:
*
* Hello
*/
*/
18 changes: 18 additions & 0 deletions trick-6-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/*
*
* Insert Magic Code Here
*
*
*/
ob_start(function ($content) {
return wordwrap($content, 5, " PHP ", true);
});
// NO CHANGES ALLOWED BELOW
echo 'Hello';
echo 'World';
/*
* Magic output:
*
* Hello PHP World
*/
9 changes: 5 additions & 4 deletions trick-6.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php

/*
*
* Insert Magic Code Here
*
*
*/
declare(ticks=3);
register_tick_function(function () {
echo ' PHP ';
});

// NO CHANGES ALLOWED BELOW

echo 'Hello';
echo 'World';

/*
* Magic output:
*
* Hello PHP World
*/
*/
9 changes: 5 additions & 4 deletions trick-7.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

/*
* Insert Magic Code Here
*/

// NO CHANGES ALLOWED BELOW
ob_start(function ($content) {
return strrev($content);
}, 1024);

// NO CHANGES ALLOWED BELOW
echo 'Foobar';
echo PHP_EOL;
echo 'Hello World';

/*
* Magic output:
*
* dlroW olleH
* rabooF
*/
*/