summaryrefslogtreecommitdiffstats
path: root/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'functions.php')
-rw-r--r--functions.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/functions.php b/functions.php
new file mode 100644
index 0000000..b6bb5f3
--- /dev/null
+++ b/functions.php
@@ -0,0 +1,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>
+