1
0
mirror of https://github.com/restoreddev/phpapprentice.git synced 2025-08-06 14:56:58 +02:00

Added classes-constructor and removed description from templates

This commit is contained in:
Andrew Davis
2018-09-03 11:52:41 -05:00
parent bf108af8e3
commit 80a4cb5f4b
5 changed files with 58 additions and 16 deletions

View File

@@ -5,7 +5,7 @@
<meta charset="utf-8">
<title><?= $title ?? 'PHP Apprentice' ?></title>
<meta name="description" content="<?= $description ?? 'A site for learning how to use PHP'?>">
<meta name="description" content="<?= $subtitle ?? 'A site for learning how to use PHP' ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/css/site.css">

View File

@@ -14,6 +14,7 @@
<li><a href="<?= page_path('classes') ?>">Classes: Introduction</a></li>
<li><a href="<?= page_path('classes-inheritance') ?>">Classes: Inheritance</a></li>
<li><a href="<?= page_path('classes-visibility') ?>">Classes: Visibility</a></li>
<li><a href="<?= page_path('classes-constructor') ?>">Classes: Constructor</a></li>
</ol>
<a href="<?= page_path('credits') ?>">Credits</a>
</div>

View File

@@ -1,4 +1,4 @@
<?php partial('header', ['title' => $title, 'description' => $description]) ?>
<?php partial('header', ['title' => $title, 'subtitle' => $subtitle]) ?>
<div class="menu">
<button class="menu-button" title="Open Menu">

View File

@@ -0,0 +1,47 @@
<?php
// Whenever you create an object in PHP, you put parentheses after the class name.
// In the previous examples, we always left the parentheses empty.
class Hat {
public $color;
public function setColor($color)
{
$this->color = $color;
}
}
$hat = new Hat();
// However, you can actually pass data into the parentheses like a function.
// The data will be passed to a special function on the class called a constructor.
class Ballcap
{
public $color;
public function __construct($color )
{
$this->color = $color;
}
}
// A constructor is not required, but can make creating a new object easier.
// They are usually used to define the initial value of a property.
// Instead of writing:
$hat = new Hat();
$hat->setColor('Red');
// You can write:
$ballcap = new Ballcap('Blue');
// Constructors do not return values because the return value is a always a new object.
class Tophat
{
public function __construct($color)
{
return $color;
}
}
// "$tophat" now holds an instance of Tophat, not the color "Grey".
$tophat = new Tophat('Grey');

View File

@@ -15,84 +15,78 @@ return [
Page::create('basics', null, 'basics.php', [
'title' => 'Basics',
'subtitle' => 'Getting started',
'description' => 'Let us get started with the basics.',
'next' => 'variables',
]),
Page::create('variables', null, 'variables.php', [
'title' => 'Variables',
'subtitle' => 'The building blocks of PHP',
'description' => '',
'previous' => 'basics',
'next' => 'arithmetic',
]),
Page::create('arithmetic', null, 'arithmetic.php', [
'title' => 'Arithmetic',
'subtitle' => 'Doing math like a pro',
'description' => '',
'previous' => 'variables',
'next' => 'comparisons',
]),
Page::create('comparisons', null, 'comparisons.php', [
'title' => 'Comparisons',
'subtitle' => 'Equality checking',
'description' => '',
'previous' => 'arithmetic',
'next' => 'boolean-logic',
]),
Page::create('boolean-logic', null, 'boolean-logic.php', [
'title' => 'Boolean Logic',
'subtitle' => 'Is it a yes or a no?',
'description' => '',
'previous' => 'comparisons',
'next' => 'conditionals',
]),
Page::create('conditionals', null, 'conditionals.php', [
'title' => 'Conditionals',
'subtitle' => 'Checking the if before the what',
'description' => '',
'previous' => 'boolean-logic',
'next' => 'loops',
]),
Page::create('loops', null, 'loops.php', [
'title' => 'Loops',
'subtitle' => 'Increase your repetitions',
'description' => '',
'previous' => 'conditionals',
'next' => 'arrays',
]),
Page::create('arrays', null, 'arrays.php', [
'title' => 'Arrays',
'subtitle' => 'Time to make a list',
'description' => '',
'previous' => 'loops',
'next' => 'functions',
]),
Page::create('functions', null, 'functions.php', [
'title' => 'Functions',
'subtitle' => 'Reusable code',
'description' => '',
'previous' => 'arrays',
'next' => 'classes',
]),
Page::create('classes', null, 'classes.php', [
'title' => 'Classes',
'subtitle' => 'Object-oriented programming',
'description' => '',
'previous' => 'functions',
'next' => 'classes-inheritance',
]),
Page::create('classes-inheritance', null, 'classes-inheritance.php', [
'title' => 'Classes Inheritance',
'title' => 'Classes: Inheritance',
'subtitle' => 'Extend your objects',
'description' => '',
'previous' => 'classes',
'next' => 'classes-visibility',
]),
Page::create('classes-visibility', null, 'classes-visibility.php', [
'title' => 'Classes Visibility',
'title' => 'Classes: Visibility',
'subtitle' => 'Privatizing your objects',
'description' => '',
'previous' => 'classes-inheritance',
'next' => 'classes-constructor',
]),
Page::create('classes-constructor', null, 'classes-constructor.php', [
'title' => 'Classes: Constructor',
'subtitle' => 'Construct your objects',
'previous' => 'classes-visibility',
'next' => '',
]),
],