mirror of
https://github.com/restoreddev/phpapprentice.git
synced 2025-08-05 22:37:45 +02:00
Continuing transition to hugo
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Variables"
|
||||
description = "The building blocks of PHP"
|
||||
tags = ["php", "variables"]
|
||||
slug = "variables"
|
||||
previous = "basics.html"
|
||||
next = "arithmetic.html"
|
||||
+++
|
||||
The variable is the basic building block of any programming language.
|
||||
In PHP, all variables start with a dollar sign.
|
||||
```php
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Arithmetic"
|
||||
description = "Doing math like a pro"
|
||||
tags = ["php", "arithmetic", "math"]
|
||||
slug = "arithmetic"
|
||||
previous = "variables.html"
|
||||
next = "strings.html"
|
||||
+++
|
||||
Now that we know how to create variables, let's look at doing some math.
|
||||
```php
|
||||
<?php
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Strings"
|
||||
description = "Working with text"
|
||||
tags = ["php", "strings"]
|
||||
slug = "strings"
|
||||
previous = "arithmetic.html"
|
||||
next = "comparisons.html"
|
||||
+++
|
||||
As seen in the first chapter, a string is a group of characters created by
|
||||
surrounding text in single or double quotes.
|
||||
```php
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Comparisons"
|
||||
description = "Equality checking"
|
||||
tags = ["php", "comparisons"]
|
||||
slug = "comparisons"
|
||||
previous = "strings.html"
|
||||
next = "boolean-logic.html"
|
||||
+++
|
||||
A boolean is a value that is always 0 or 1, yes or no, on or off.
|
||||
In PHP, a boolean is represented by the words true and false.
|
||||
While programming, you will often want to know if something is positive or negative.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Boolean Logic"
|
||||
description = "Is it a yes or a no?"
|
||||
tags = ["php", "booleans"]
|
||||
slug = "boolean-logic"
|
||||
previous = "comparisons.html"
|
||||
next = "conditionals.html"
|
||||
+++
|
||||
Boolean logic is used to combine booleans to return another boolean.
|
||||
|
||||
Using double ampersands tells PHP to check if both values are true.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Conditionals"
|
||||
description = "Checking the if before the what"
|
||||
tags = ["php", "conditionals", "if", "switch"]
|
||||
slug = "conditionals"
|
||||
previous = "boolean-logic.html"
|
||||
next = "loops.html"
|
||||
+++
|
||||
When writing code, there will be times when you need to perform actions only under certain circumstances.
|
||||
There are several ways to control execution in PHP.
|
||||
We will start with an if statement.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Loops"
|
||||
description = "Increase your repetitions"
|
||||
tags = ["php", "loop", "foreach", "for"]
|
||||
slug = "loops"
|
||||
previous = "conditionals.html"
|
||||
next = "arrays.html"
|
||||
+++
|
||||
A loop tells PHP to run a block of code more than once.
|
||||
A classic loop is a while loop.
|
||||
A `while` loop will continue to run the block of code as long as the value in parentheses is true.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Arrays"
|
||||
description = "Time to make a list"
|
||||
tags = ["php", "array", "list"]
|
||||
slug = "arrays"
|
||||
previous = "loops.html"
|
||||
next = "functions.html"
|
||||
+++
|
||||
In PHP, arrays are used to store a list of items in a single variable.
|
||||
There are two ways to create an array.
|
||||
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Functions"
|
||||
description = "Reusable code"
|
||||
tags = ["php", "function"]
|
||||
slug = "functions"
|
||||
previous = "arrays.html"
|
||||
next = "classes.html"
|
||||
+++
|
||||
A function allows you to store code under a name and then execute
|
||||
that code later.
|
||||
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Classes"
|
||||
description = "Object-oriented programming"
|
||||
tags = ["php", "class", "object-oriented programming"]
|
||||
slug = "classes"
|
||||
previous = "functions.html"
|
||||
next = "classes-inheritance.html"
|
||||
+++
|
||||
Classes allow you to define your own data types. All classes start with the
|
||||
class keyword followed by the name of the class and opening and closing curly braces.
|
||||
```php
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Classes: Inheritance"
|
||||
description = "Extend your objects"
|
||||
tags = ["php", "extend", "inheritance"]
|
||||
slug = "classes-inheritance"
|
||||
previous = "classes.html"
|
||||
next = "classes-visibility.html"
|
||||
+++
|
||||
In PHP, a class can extend another class, inheriting the parent class'
|
||||
properties and methods. To make a class a child of another, use the `extends`
|
||||
keyword after the class name.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Classes: Visibility"
|
||||
description = "Privatizing your objects"
|
||||
tags = ["php", "private", "protected", "visibility"]
|
||||
slug = "classes-visibility"
|
||||
previous = "classes-inheritance.html"
|
||||
next = "classes-constructor.html"
|
||||
+++
|
||||
In the last chapter, we defined properties and methods on the class using the public keyword.
|
||||
You can also define them using the `protected` and `private` keywords.
|
||||
Both keywords prevent the properties and functions from being accessible outside the object.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Classes: Constructor"
|
||||
description = "Construct your objects"
|
||||
tags = ["php", "construct", "constructor", "new"]
|
||||
slug = "classes-constructor"
|
||||
previous = "classes-visibility.html"
|
||||
next = "static.html"
|
||||
+++
|
||||
Whenever you create an object in PHP, you put parentheses after the class name.
|
||||
In the previous examples, we always left the parentheses empty.
|
||||
```php
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Static"
|
||||
description = "Class properties and methods"
|
||||
tags = ["php", "static"]
|
||||
slug = "static"
|
||||
previous = "classes-constructor.html"
|
||||
next = "interfaces.html"
|
||||
+++
|
||||
When writing a class, all of the properties and methods are being defined for the object
|
||||
that will be created from the class.
|
||||
```php
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Interfaces"
|
||||
description = "Writing code contracts"
|
||||
tags = ["php", "interface"]
|
||||
slug = "interfaces"
|
||||
previous = "static.html"
|
||||
next = "abstract.html"
|
||||
+++
|
||||
The word `interface` is a confusing term because it is used for so many different concepts.
|
||||
Most often, we use it to describe the appearance of an app and how a user interacts with it.
|
||||
However, in PHP, an interface is a special construct that acts as a contract for classes.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Abstract"
|
||||
description = "Inheriting an interface"
|
||||
tags = ["php", "abstract"]
|
||||
slug = "abstract"
|
||||
previous = "interfaces.html"
|
||||
next = "exceptions.html"
|
||||
+++
|
||||
Abstract classes are similar to interfaces in that they define methods that a sub-class must implement.
|
||||
However, an abstract class can also have normal methods. To create an abstract class, use the `abstract`
|
||||
keyword followed by `class` and the name of the class.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "Exceptions"
|
||||
description = "Throwing errors"
|
||||
tags = ["php", "exception"]
|
||||
slug = "exceptions"
|
||||
previous = "abstract.html"
|
||||
next = "web/http.html"
|
||||
+++
|
||||
Sometimes things go wrong when someone uses your code. How do we handle this situation?
|
||||
PHP has Exceptions to define errors and the ability to `throw` them to stop code
|
||||
execution and tell the user of your code that something is wrong.
|
||||
|
33
content/credits.md
Normal file
33
content/credits.md
Normal file
@@ -0,0 +1,33 @@
|
||||
+++
|
||||
title = "Credits"
|
||||
+++
|
||||
<div>
|
||||
<p>
|
||||
PHP Apprentice was inspired by
|
||||
<a href="https://gobyexample.com/">Go By Example</a> and by <a href="https://elixirschool.com/">Elixir School</a>. Both sites offer excellent, quality documentation in Go and Elixir and I want PHP Apprentice to provide the same
|
||||
experience for the PHP programming language.
|
||||
</p>
|
||||
<p>
|
||||
Sites used as a reference while writing PHP Apprentice:
|
||||
<ul>
|
||||
<li><a href="https://secure.php.net/" target="_blank">php.net</a></li>
|
||||
<li><a href="https://www.phptherightway.com/" target="_blank">PHP The Right Way</a></li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
PHP Apprentice was built using several open source projects, besides PHP itself.
|
||||
Thank you to each of these maintainers for providing great libraries!
|
||||
<ul>
|
||||
<li><a href="https://prismjs.com/" target="_blank">Prism.js</a></li>
|
||||
<li><a href="https://www.zondicons.com/" target="_blank">Zondicons by Steve Schoger</a></li>
|
||||
<li><a href="https://postcss.org/" target="_blank">PostCSS</a></li>
|
||||
<li><a href="https://symfony.com/doc/current/components/console.html" target="_blank">Symfony CLI</a></li>
|
||||
<li><a href="https://symfony.com/doc/current/frontend.html" target="_blank">Symfony Encore</a></li>
|
||||
<li><a href="https://parsedown.org/" target="_blank">Parsedown</a></li>
|
||||
</ul>
|
||||
</p>
|
||||
<hr />
|
||||
<p>
|
||||
Created and managed by <a href="https://twitter.com/restoreddev" target="_blank">Andrew Davis @restoreddev</a>.
|
||||
</p>
|
||||
</div>
|
22
content/installing-php.md
Normal file
22
content/installing-php.md
Normal file
@@ -0,0 +1,22 @@
|
||||
+++
|
||||
title = "Installing PHP"
|
||||
+++
|
||||
<div>
|
||||
<h2>Windows 10</h2>
|
||||
<ol class="body-ol">
|
||||
<li>Download PHP from the <a href="https://windows.php.net/download">PHP For Windows</a> site. I recommend downloading the non-thread safe PHP 7.1 or 7.2 (unless you want to use Apache and you know if you do). You will also need to choose 32 bit (x86) or 64 bit (x64) depending on your version of Windows.</li>
|
||||
<li>Download the corresponding Visual C++ Redistributable from the same site. For PHP 7.1, it is VC14 and for PHP 7.2, it is VC15.</li>
|
||||
<li>Install the VC redistrubutable using the downloaded executable.</li>
|
||||
<li>The PHP download comes in a zip folder. Extract the zip folder into your user directory in a folder named <code>php</code>. The path should look like <code>C:\Users\username\php</code>.</li>
|
||||
<li>Next, we need to add PHP to your environment variables path. Open "System" under "Control Panel". Go to the "Advanced" tab and select "Environment Variables". In the "User variables" section, select "Path" and click the "Edit" button. You will see a list of different folder paths. Add the PHP path to the list using the "Add" button. The PHP path is the same folder where you extracted PHP.</li>
|
||||
<li>Now, you can open PowerShell or Command Prompt and type <code>php -v</code> to verify PHP was installed correctly. It will return the installed version of PHP on your system.</li>
|
||||
</ol>
|
||||
|
||||
<h2>MacOS</h2>
|
||||
<p>Good news! Each version of MacOS comes with PHP by default. However, if you are running an older version of MacOS or OS X, then you will need to manually install a new version of PHP. To check your current version, open Terminal and type <code>php -v</code>. You will need at least PHP 7.1 on your computer to use all the features in these tutorials.</p>
|
||||
<ol class="body-ol">
|
||||
<li>Install <a href="https://brew.sh/">Homebrew</a>.</li>
|
||||
<li>Run <code>brew install php</code> in Terminal.</li>
|
||||
<li>Check your version is correct by running <code>php -v</code> in Terminal.</li>
|
||||
</ol>
|
||||
</div>
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "HTTP"
|
||||
description = "Understanding the format of the web"
|
||||
tags = ["web", "http"]
|
||||
slug = "http"
|
||||
previous = "exceptions.html"
|
||||
next = "web/http-post.html"
|
||||
+++
|
||||
HTTP stands for Hypertext Transfer Protocol. It is a standard for how requests and responses should be formatted for
|
||||
a server and a web browser. When you open a link in your web browser, you are sending a HTTP request to a server and it
|
||||
is responding with a HTTP response. The browser then takes the response, parses it and displays it to the user.
|
||||
|
@@ -1,3 +1,11 @@
|
||||
+++
|
||||
title = "HTTP Post"
|
||||
description = "Sending data to a server"
|
||||
tags = ["web", "http", "post"]
|
||||
slug = "http-post"
|
||||
previous = "web/http.html"
|
||||
next = "web/http-server.html"
|
||||
+++
|
||||
HTTP uses multiple different request types for indicating actions that should be performed on the server. The most common ones
|
||||
you will use are:
|
||||
- GET -> Retrieve a resource
|
||||
|
@@ -1,3 +1,10 @@
|
||||
+++
|
||||
title = "PHP HTTP Server"
|
||||
description = "Handling HTTP Requests in PHP"
|
||||
tags = ["php", "http", "server"]
|
||||
slug = "http-server"
|
||||
previous = "web/http-post.html"
|
||||
+++
|
||||
In PHP, you usually use a separate web server program that accepts HTTP requests and passes them to PHP to create a response. Common examples of separate web server programs are Apache and Nginx. However, PHP has a built in web server we can use during development.
|
||||
|
||||
To use the development web server, open a terminal and a new folder for holding your code. Create a file called `index.php` and put this PHP code in it:
|
||||
|
Reference in New Issue
Block a user