summaryrefslogtreecommitdiffstats
path: root/functions.php
blob: b6bb5f3b556cd99ad9db758f1de982fd9df6e00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hacker's Corner</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Please Don't Fear!</h1>
<b>Sandbox:</b> Let's Roll!<br />
<p>
    <?php
        error_reporting(E_ALL | E_STRICT);
        ini_set("display_errors", 1);

        /* pass by reference, otherwise arguments get duped */
        function calc_square(&$var)
        {
            $var *= $var;
        }

        function num_raised(&$var, $base = 2, $pow = 3) /* yeah */
        {
            $var = 1;
            while ($pow--)
                $var *= $base;
        }

        /* unlike Lua, we have to pass all arguments to the functions */
        function print_pi($str)
        {
            $pi = 3.14159;
            return "Pi = " . $pi . " " . $str . ".<br />";
        }

        echo print_pi("brotato");

        $number = 11;
        calc_square($number);
        echo "a square of 11 is " . $number . ".<br />";

        $number2 = NULL; /* nice to know how to modiy a variable */
        num_raised($number2, 2, 4);
        echo "a cube of 2 is " . $number2 . ".<br />";
        var_dump($number2);
    ?>
</p>
    <p>PHP defined variables including mine.</p>
<pre>
    <?php
        print_r(get_defined_vars());
    ?>
</pre>
</body>
</html>