First Draft

First Draft of the Example Files
This commit is contained in:
RobinNixon
2020-12-10 13:21:38 +00:00
parent 77a7b57c4f
commit 0335342e00
1127 changed files with 46959 additions and 56 deletions
+5
View File
@@ -0,0 +1,5 @@
<?php
echo strrev(" .dlrow olleH"); // Reverse string
echo str_repeat("Hip ", 2); // Repeat string
echo strtoupper("hooray!"); // String to upper case
?>
+12
View File
@@ -0,0 +1,12 @@
<?php
echo fix_names("WILLIAM", "henry", "gatES");
function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return $n1 . " " . $n2 . " " . $n3;
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$names = fix_names("WILLIAM", "henry", "gatES");
echo $names[0] . " " . $names[1] . " " . $names[2];
function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return array($n1, $n2, $n3);
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
$a1 = "WILLIAM";
$a2 = "henry";
$a3 = "gatES";
echo $a1 . " " . $a2 . " " . $a3 . "<br>";
fix_names($a1, $a2, $a3);
echo $a1 . " " . $a2 . " " . $a3;
function fix_names(&$n1, &$n2, &$n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
$a1 = "WILLIAM";
$a2 = "henry";
$a3 = "gatES";
echo $a1 . " " . $a2 . " " . $a3 . "<br>";
fix_names();
echo $a1 . " " . $a2 . " " . $a3;
function fix_names()
{
global $a1; $a1 = ucfirst(strtolower($a1));
global $a2; $a2 = ucfirst(strtolower($a2));
global $a3; $a3 = ucfirst(strtolower($a3));
}
?>
+6
View File
@@ -0,0 +1,6 @@
<?php
include("library.php");
// Your code goes here
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
include_once("library.php");
// Your code goes here
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
require_once("library.php");
// Your code goes here
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
if (function_exists("array_combine"))
{
echo "Function exists";
}
else
{
echo "Function does not exist - better write our own";
}
?>
+14
View File
@@ -0,0 +1,14 @@
<?php
$object = new User;
print_r($object);
class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
?>
+20
View File
@@ -0,0 +1,20 @@
<?php
$object = new User;
print_r($object); echo "<br>";
$object->name = "Joe";
$object->password = "mypass";
print_r($object); echo "<br>";
$object->save_user();
class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
?>
+14
View File
@@ -0,0 +1,14 @@
<?php
$object1 = new User();
$object1->name = "Alice";
$object2 = $object1;
$object2->name = "Amy";
echo "object1 name = " . $object1->name . "<br>";
echo "object2 name = " . $object2->name;
class User
{
public $name;
}
?>
+14
View File
@@ -0,0 +1,14 @@
<?php
$object1 = new User();
$object1->name = "Alice";
$object2 = clone $object1;
$object2->name = "Amy";
echo "object1 name = " . $object1->name . "<br>";
echo "object2 name = " . $object2->name;
class User
{
public $name;
}
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
class User
{
function __construct($param1, $param2)
{
// Constructor statements go here
public $username = "Guest";
}
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
class Test
{
public $name = "Paul Smith"; // Valid
public $age = 42; // Valid
public $time = time(); // Invalid - calls a function
public $score = $level * 2; // Invalid - uses an expression
}
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
class User
{
public $name, $password;
function get_password()
{
return $this->password;
}
?>
+8
View File
@@ -0,0 +1,8 @@
<?php
$object1 = new User();
$object1->name = "Alice";
echo $object1->name;
class User {}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
class Test
{
public $name = "Paul Smith"; // Valid
public $age = 42; // Valid
public $time = time(); // Invalid - calls a function
public $score = $level * 2; // Invalid - uses an expression
}
?>
+17
View File
@@ -0,0 +1,17 @@
<?php
Translate::lookup();
class Translate
{
const ENGLISH = 0;
const SPANISH = 1;
const FRENCH = 2;
const GERMAN = 3;
// ...
static function lookup()
{
echo self::SPANISH;
}
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
class Example
{
var $name = "Michael"; // Same as public but deprecated
public $age = 23; // Public property
protected $usercount; // Protected property
private function admin() // Private method
{
// Admin code goes here
}
}
?>
+11
View File
@@ -0,0 +1,11 @@
<?php
User::pwd_string();
class User
{
static function pwd_string()
{
echo "Please enter your password";
}
}
?>
+17
View File
@@ -0,0 +1,17 @@
<?php
$temp = new Test();
echo "Test A: " . Test::$static_property . "<br>";
echo "Test B: " . $temp->get_sp() . "<br>";
echo "Test C: " . $temp->static_property . "<br>";
class Test
{
static $static_property = "I'm static";
function get_sp()
{
return self::$static_property;
}
}
?>
+31
View File
@@ -0,0 +1,31 @@
<?php
$object = new Subscriber;
$object->name = "Fred";
$object->password = "pword";
$object->phone = "012 345 6789";
$object->email = "fred@bloggs.com";
$object->display();
class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
class Subscriber extends User
{
public $phone, $email;
function display()
{
echo "Name: " . $this->name . "<br>";
echo "Pass: " . $this->password . "<br>";
echo "Phone: " . $this->phone . "<br>";
echo "Email: " . $this->email;
}
}
?>
+26
View File
@@ -0,0 +1,26 @@
<?php
$object = new Son;
$object->test();
$object->test2();
class Dad
{
function test()
{
echo "[Class Dad] I am your Father<br>";
}
}
class Son extends Dad
{
function test()
{
echo "[Class Son] I am Luke<br>";
}
function test2()
{
parent::test();
}
}
?>
+27
View File
@@ -0,0 +1,27 @@
<?php
$object = new Tiger();
echo "Tigers have...<br>";
echo "Fur: " . $object->fur . "<br>";
echo "Stripes: " . $object->stripes;
class Wildcat
{
public $fur; // Wildcats have fur
function __construct()
{
$this->fur = "TRUE";
}
}
class Tiger extends Wildcat
{
public $stripes; // Tigers have stripes
function __construct()
{
parent::__construct(); // Call parent constructor first
$this->stripes = "TRUE";
}
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
class User
{
final function copyright()
{
echo "This class was written by Joe Smith";
}
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
class User
{
final function copyright()
{
echo "This class was written by Joe Smith";
}
}
?>