diff --git a/chapters/abstract.md b/chapters/abstract.md index eda14a6..99b4b6b 100644 --- a/chapters/abstract.md +++ b/chapters/abstract.md @@ -1,5 +1,5 @@ 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" +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. ```php turnOn(); diff --git a/chapters/basics.md b/chapters/basics.md index 2ac6b16..3a2036a 100644 --- a/chapters/basics.md +++ b/chapters/basics.md @@ -1,6 +1,6 @@ In the tradition of our ancestors, let's start with a hello world program. -All PHP files must start with a drive(); ``` -A class can use a parent's property or method from the "$this" variable. +A class can use a parent's property or method from the `$this` variable. ```php class Motorcycle extends Vehicle { @@ -56,9 +56,9 @@ $cycle = new Motorcycle(); $cycle->pushPedal(); ``` -If you override a parent's property or method, the "$this" variable will refer to the child's +If you override a parent's property or method, the `$this` variable will refer to the child's implementation of the property or method. To call the parent's property or method explicity, -use the "parent" keyword. +use the `parent` keyword. ```php class Racecar extends Vehicle { diff --git a/chapters/classes-visibility.md b/chapters/classes-visibility.md index f24524d..ff36fb6 100644 --- a/chapters/classes-visibility.md +++ b/chapters/classes-visibility.md @@ -1,5 +1,5 @@ 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. +You can also define them using the `protected` and `private` keywords. Both keywords prevent the properties and functions from being accessible outside the object. Only the object itself can use each. ```php @@ -16,7 +16,7 @@ class Phone } ``` -We cannot set the number using "$phone->number = '123-456-7890'". +We cannot set the number using `$phone->number = '123-456-7890'`. Instead, we can use the public method. ```php $phone = new Phone(); @@ -39,9 +39,9 @@ class Phone2 } ``` -The "protected" and "private" keywords work a little differently. +The `protected` and `private` keywords work a little differently. They both prevent functions and properties from being accessed outside an object. -However, a method or property marked "protected" can still be accessed by a child class. +However, a method or property marked `protected` can still be accessed by a child class. ```php class Phone3 { @@ -56,8 +56,8 @@ class Phone3 } ``` -In class "Smartphone", the "caller" property is accessible because the parent class -has it marked as "protected". However, "Smartphone" cannot access the "number" property +In class `Smartphone`, the `caller` property is accessible because the parent class +has it marked as `protected`. However, `Smartphone` cannot access the `number` property because it is still listed as private. ```php class Smartphone extends Phone3 diff --git a/chapters/classes.md b/chapters/classes.md index 413c688..8e7fa5e 100644 --- a/chapters/classes.md +++ b/chapters/classes.md @@ -1,4 +1,3 @@ - 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 @@ -9,7 +8,7 @@ class Car } ``` -To create an instance of a class, you use the "new" keyword in front of the class name +To create an instance of a class, you use the `new` keyword in front of the class name with parentheses. ```php $car = new Car(); @@ -17,7 +16,7 @@ $car = new Car(); A class can define attributes and methods. An attribute is a piece of data stored on the class instance. You can define an attribute by adding the -word "public" and a variable name inside the class definition. +word `public` and a variable name inside the class definition. ```php class Bicycle { @@ -26,7 +25,7 @@ class Bicycle ``` Then, when you create an instance of the class, you can set and use -the color attribute on the bicycle using "->". +the color attribute on the bicycle using `->`. ```php $bike = new Bicycle(); $bike->color = 'Blue'; @@ -42,8 +41,8 @@ echo $redBike->color . " Bike Object\n"; ``` A method is a function attached to the class. You can add a method -to a class by using the "public" keyword followed by the function. A method -can access the attributes and methods of an object instance using the "$this" variable. +to a class by using the `public` keyword followed by the function. A method +can access the attributes and methods of an object instance using the `$this` variable. ```php class Tricycle { @@ -56,7 +55,7 @@ class Tricycle } ``` -You can execute a method on an object using the same "->" arrow characters. +You can execute a method on an object using the same `->` arrow characters. ```php $bike = new Tricycle(); $bike->color = 'Red'; diff --git a/chapters/comparisons.md b/chapters/comparisons.md index dfb45cf..f29dd11 100644 --- a/chapters/comparisons.md +++ b/chapters/comparisons.md @@ -1,4 +1,3 @@ - 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. @@ -48,7 +47,7 @@ $one >= $two; You can also check that two values are equal and of the same type by using three equal signs. -This returns true. +The following comparisons return true. ```php 1 == 1; 1 == '1'; @@ -57,7 +56,7 @@ This returns true. 1 === 1; ``` -This returns false. +These return false. ```php 1 === '1'; 1 === true; diff --git a/chapters/conditionals.md b/chapters/conditionals.md index 712cf04..3c28948 100644 --- a/chapters/conditionals.md +++ b/chapters/conditionals.md @@ -1,4 +1,3 @@ - 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. @@ -12,10 +11,10 @@ if ($animal == 'cow') { ``` All conditionals check to see if a statement evaluates to true or false. -In the case above, since $animal equals 'cow', the statement returns true and the contents of the if statement are executed. +In the case above, since `$animal` equals 'cow', the statement returns true and the contents of the if statement are executed. An if statement can have multiple conditions chained together. -If the first if statement returns false, then PHP will check each elseif. +If the first if statement returns false, then PHP will check each `elseif`. If none of the checks return true, then the else block will be executed. ```php $animal = 'bird'; @@ -32,7 +31,7 @@ if ($animal == 'dog') { An alternative to the if statement is the switch. A switch statement has multiple cases to check if the value in parentheses equals something. -In this statement, since $food equals 'apples', the switch will echo "Eating an apple". +In this statement, since `$food` equals 'apples', the switch will echo "Eating an apple". The default case will be run if no other case evaluates to true, like an else statement. ```php $food = 'apples'; diff --git a/chapters/exceptions.md b/chapters/exceptions.md index 90c7e05..9cef6bf 100644 --- a/chapters/exceptions.md +++ b/chapters/exceptions.md @@ -1,5 +1,5 @@ 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 +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. ```php charge('1234'); A developer who wants to prevent an exception from stopping code execution can catch the exception and use it for logging or display the error to a user. -Just wrap the code that might throw an exception with the keyword "try" and brackets -followed by "catch", the exception type in parentheses and more brackets. +Just wrap the code that might throw an exception with the keyword `try` and brackets +followed by `catch`, the exception type in parentheses and more brackets. ```php try { $processor->charge('1234'); @@ -37,7 +37,7 @@ try { ``` You can make your own custom exceptions as well. They are just classes -that extend Exception. +that extend the `Exception` class. ```php class MyCustomException extends Exception {} ``` @@ -51,8 +51,8 @@ try { } ``` -Since all exceptions inherit from Exception, catching -Exception will catch any and all exceptions that might be thrown. +Since all exceptions inherit from `Exception`, catching +`Exception` will catch any and all exceptions that might be thrown. ```php try { throw new MyCustomException('I inherit from Exception'); diff --git a/chapters/functions.md b/chapters/functions.md index 6aaa8ac..6e6fa85 100644 --- a/chapters/functions.md +++ b/chapters/functions.md @@ -27,8 +27,8 @@ function greet($firstname, $lastname) { ``` Then, you can pass in values when calling a function. In the greet function, -'John' is assigned to $firstname and 'Smith' is assigned to -$lastname. +'John' is assigned to `$firstname` and 'Smith' is assigned to +`$lastname`. ```php greet('John', 'Smith'); ``` diff --git a/chapters/interfaces.md b/chapters/interfaces.md index ae0f646..9d72f83 100644 --- a/chapters/interfaces.md +++ b/chapters/interfaces.md @@ -1,4 +1,4 @@ -The word "interface" is a confusing term because it is used for so many different concepts. +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. An interface defines what methods a class should have. @@ -12,8 +12,8 @@ interface Chair } ``` -To use an interface with a class, you use the "implements" keyword after the class name. -Now, the Recliner class must have a setColor method and a setLegs method. +To use an interface with a class, you use the `implements` keyword after the class name. +Now, the `Recliner` class must have a `setColor` method and a setLegs method. If you do not create the required methods on the class, PHP will throw an error. ```php class Recliner implements Chair @@ -53,7 +53,7 @@ class CreditCard } ``` -Since CreditCard implements Payment, other developers can use the charge method, knowing it exists on the class. +Since `CreditCard` implements `Payment`, other developers can use the charge method, knowing it exists on the class. ```php $creditCard = new CreditCard(); $creditCard->charge(25); diff --git a/chapters/loops.md b/chapters/loops.md index b4eabfc..3a4f84d 100644 --- a/chapters/loops.md +++ b/chapters/loops.md @@ -1,6 +1,6 @@ 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. +A `while` loop will continue to run the block of code as long as the value in parentheses is true. ```php 0) { } ``` -A "do while" loop is similar to a "while" loop except it always runs at least -one iteration. In a classic "while" loop, no iterations may be executed if -the value in parentheses is false. In a "do while", the boolean check +A `do while` loop is similar to a `while` loop except it always runs at least +one iteration. In a classic `while` loop, no iterations may be executed if +the value in parentheses is false. In a `do while`, the boolean check is not done until after the execution of an iteration. ```php $num = 0; @@ -23,7 +23,7 @@ do { } while ($num < 5); ``` -"for" loops allow you to create a more concise while loop. +`for` loops allow you to create a more concise while loop. Inside the parentheses, the left section creates a variable before the loop starts, the middle section is the check that is done at the beginning of each loop and the third section is executed after each loop. @@ -33,9 +33,9 @@ for ($i = 0; $i < 10; $i++) { } ``` -A "foreach" loop allows you to easily loop over an array. +A `foreach` loop allows you to easily loop over an array. An array is a list of data stored together. -The "as" keyword lets you assign a variable to the value +The `as` keyword lets you assign a variable to the value in the array for the current iteration of the loop. ```php $set = [1, 2, 3, 4, 5]; @@ -44,7 +44,7 @@ foreach ($set as $num) { } ``` -In loops, you can use the keyword "break" to stop the loop execution +In loops, you can use the keyword `break` to stop the loop execution no matter how many more iterations should run. ```php $values = ['one', 'two', 'three']; @@ -56,7 +56,7 @@ foreach ($values as $value) { } ``` -The "continue" keyword stops executing the current loop iteration, +The `continue` keyword stops executing the current loop iteration, but then allows the loop to continue with other iterations. ```php $values = ['one', 'skip', 'three']; diff --git a/chapters/static.md b/chapters/static.md index 3afdfc7..f2b33da 100644 --- a/chapters/static.md +++ b/chapters/static.md @@ -22,7 +22,7 @@ $house = new House('Green'); ``` However, what if you want the blueprint to have properties and methods? -That is when you use the "static" keyword. In this class, we will define a default color +That is when you use the `static` keyword. In this class, we will define a default color on the class itself and then use it when creating a new object. ```php class Skyscraper @@ -42,7 +42,7 @@ class Skyscraper } ``` -You can access static methods and properties using double colons on "self" inside the object +You can access static methods and properties using double colons on `self` inside the object or on the class name outside of the object. Static methods and properties can only access other static methods and properties. ```php @@ -75,7 +75,7 @@ class TinyHouse } ``` -Using "build" can make more sense than "new", but it is ultimately a personal preference. +Using `build` can make more sense than `new`, but it is ultimately a personal preference. ```php $house = TinyHouse::build('Blue', 4, true); ``` diff --git a/chapters/strings.md b/chapters/strings.md index cdc70b7..0c78b07 100644 --- a/chapters/strings.md +++ b/chapters/strings.md @@ -8,7 +8,7 @@ $lastname = "Johnson"; ``` A double quoted string can interpret special characters starting -with a back slash to create formatting. The \n creates a newline +with a back slash to create formatting. The `\n` creates a newline between the names and after them. ```php echo "Jacob\nJones\n"; diff --git a/chapters/variables.md b/chapters/variables.md index f7659e1..43a57e7 100644 --- a/chapters/variables.md +++ b/chapters/variables.md @@ -1,4 +1,3 @@ - The variable is the basic building block of any programming language. In PHP, all variables start with a dollar sign. ```php