Skip to content

Instantly share code, notes, and snippets.

@joelbrennan0
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelbrennan0/93750c1e96b16d18907b to your computer and use it in GitHub Desktop.
Save joelbrennan0/93750c1e96b16d18907b to your computer and use it in GitHub Desktop.
PHP CLASSES - Basics of a class:
<?php
class Task {
public $title;
public $description;
public function __construct($title, $description) {
$this->title = $title;
$this->description = $description;
}
}
?>
<?php
/*===================================
CLASSES - a hypothetical task list
===================================*/
include 'Task.php';
$task1 = new Task('Milk', 'get two pints of milk from the shop');
$task2 = new Task('Traniers', 'buy a new pair of running shoes');
$tasks = array($task1, $task2);
?>
<h1>Tasks</h1>
<?php foreach ($tasks as $task) : ?>
<h2><?php echo $task->title ?></h2>
<p><?php echo $task->description ?></p>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment