Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

English #341

Merged
merged 7 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions description.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

title: |
Learn PHP Online in 25 Hours
header: |
Learn PHP Online in 25 Hours
description: |
Learning to program is not an easy and time-consuming process. Learning the syntax of the language is the easiest and shortest part of the journey, but you can't start without it. This course is devoted to the basics of writing programs in PHP. It prepares the groundwork for writing meaningful programs
seo_description: |
Learn new skills with PHP: free online training | 72 lessons in programming fundamentals with lots of practice | Advance your knowledge and career with a free online PHP course

keywords:
- php
- code basics
- online course
- free course
- programming
36 changes: 31 additions & 5 deletions modules/10-basics/10-hello-world/description.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,41 @@

name: Hello, World!
theory: |
It's a long-lasting tradition: our first program will be called "Hello, World!". Copy the code precisely from the instructions into the editor and Run it. Notice: case matters! Uppercase characters and lowercase characters are not the same. Remember to notice this in future.
As is our tradition, we'll begin by writing the 'Hello, World!' program. The program will print the following text:

<pre class='hexlet-basics-output'>
Hello, World!
</pre>

Output to the screen is done with a special command `echo`, followed by a single or double-quoted string to be output. Be sure to put a semicolon at the end.

```php
<?php

echo 'Hello, World!'; // => Hello, World!
```

https://replit.com/@hexlet/php-basics-hello-world-echo

There are other ways to display a string on the screen. For example, you can use the function (a concept we will get to know later) `print_r()`. In this case, the string is entered in parentheses immediately after the function name. You also need to put `;` at the end.

```php
<?php

print_r('Hello, World!');
```

https://replit.com/@hexlet/php-basics-hello-world-printr

In simple situations, there's no difference between these constructions. You can use either one method of output or the other. In more complex cases, where you want to display not just numbers or strings, but, for example, arrays, `echo` won't be able to do this, but `print_r()` will display everything.

instructions: |
Type the following into the editor:
Copy the exact code from the instructions into the editor and run it by clicking «Run».

```php
<?php
print_r('Winter is coming!');

print_r('Hello, World!');
```

tips:
- "If there are `// BEGIN` and `// END` words in the editor, then write your code between those lines."
Note: If you write `heLLo, woRld!` instead of `Hello, World!`, it will be considered different text because upper and lower case letters are different characters. _Case is important!_ This rule affects almost everything in coding, so make sure you get used to paying close attention to the case at all times.
13 changes: 9 additions & 4 deletions modules/10-basics/20-tags/description.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

name: Tags
theory: |
PHP is probably the only language where you can't start coding right away, because the interpreter (a program that executes code) will evaluate your code as plain text. Any code in PHP should be wrapped in `<?php ?>`.
PHP is probably the only language in which you can't start writing code right away. Such code will be perceived by the interpreter (the program executing the code) as plain text. Any PHP code should be wrapped in a `<?php ?>` construct.

PHP allows you not to specify the closing tag `?>`. In our lessons we will be omitting it and it won't affect anything. But coding standards (rules on how to write code) in different companies require adding the closing tag `?>`.
`<?php` is the opening tag and `?>` is the closing tag. PHP allows you to omit the closing part `?>`. And the PSR-12 code manual doesn't let you include it at all.

instructions: |
Type the following code into the editor and don't forget that it should start with `<?php`.
Type the code from the example, and put the `<?php` tag at the beginning:

```php
<?php
Expand All @@ -16,4 +16,9 @@ instructions: |
```

tips:
- "[Coding standards (psr-1)](https://www.php-fig.org/psr/psr-1/)"
- "[Basic Code Writing Standard (PSR-1)](https://www.php-fig.org/psr/psr-1/)"
- "[Code Design Guide (PSR-12)](https://www.php-fig.org/psr/psr-12/)"

definitions:
- name: Interpreter
description: "a program that executes code written in a programming language."
38 changes: 27 additions & 11 deletions modules/10-basics/30-comments/description.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@

name: Comments
theory: |
Almost all the programming languages allow you to add comments to your code. Comments are read only by humans - the interpreter doesn't evaluate them. Comments serve as notes for those who wrote them and other developers. There are two types of comments in php:

**Single line comments** start with `//`. Whatever follows after will not be evaluated or executed.
Almost every programming language allows you to add comments to your code. This is text that isn't part of the program and is needed for programmers to make notes. They help explain how the code works, what errors need to be corrected, or what not to forget to add later.

A comment can take up the whole line:
Comments in PHP come in two flavors:

## Single line comments

_Single line comments start with `//`. Any text can go after these characters, the whole line will be left alone when the program is run.

A comment can take up a whole line. Or you can create several comments if one line isn't enough:

```php
<?php

// For Winterfell!
// For Lanisters!
```

or can follow some code on the same line:
Or it can go after code on the same line:

```php
<?php

print_r('I am the King'); // => For Lannisters!
print_r('I am the King'); // For Lannisters!
```

**Multiline comments** start with `/*` and end with `*/`. Each line between them should start with a `*`.
## Multi-line comments

_Multiline comments_ start with `/*` and end with `*/`. Each line between them must begin with a `*`.

```php
<?php

/*
* The night is dark and
* full of terrors.
Expand All @@ -35,10 +41,20 @@ theory: |
```

instructions: |
Create a single line comment with the folowing text: `You know nothing, Jon Snow!`.
Create a one-line comment with the text: `You know nothing, Jon Snow!`.

tips: []

definitions:
- name: "Comment"
description: "A comment is just a text and it doesn't affect program execution. Programmers use it to add notes for themselves and for their colleagues"
- name: Comment
description: |
text in program code that doesn't affect functionality, and is added by programmers for themselves and their colleagues.

`// single-line comment`

```
/*
* multiline comment
* multiline comment
*/
```
43 changes: 31 additions & 12 deletions modules/10-basics/40-instructions/description.en.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,53 @@
---

name: Instructions
name: Statements
theory: |
A statement is a command given to a computer to do something. Code in PHP is a collection of instructions, usually separated from each other by a `;`.

Instruction is a command given to computer. PHP code is a set of instructions separated by `;`.

Here is an example of code with two instructions. When you run this code you will see two sentences on the screen, one after the other.
Here's an example of some code with two statements.

```php
<?php

print_r('Mother of Dragons');
print_r('Mother of Dragons. ');
print_r('Dracarys!');
```

Actually, it's possible to put multiple instructions on the same line:
When you run this code, two sentences are displayed in sequence:

<pre class='hexlet-basics-output'>
Mother of Dragons. Dracarys!
</pre>

Theoretically, the instructions can be written one after the other without moving them to a new line:

```php
<?php

print_r('Mother of Dragons'); print_r('Drakarys!');
print_r('Mother of Dragons.'); print_r('Drakarys!');
```

but it's considered bad practice.
But it's considered bad practice as it's difficult to read.

Why is it important to know? A statement is a unit of execution. The interpreter is a program that runs the code in PHP and executes the instructions strictly in order. An interpreter's principle of operation is (approximately) as follows. It reads the file with the code, splits the code into statements, and then executes them.

instructions: |
Output these three names on the screen, one after the other: "Robert", "Stannis", "Renly".
Print these three names, one after the other: _Robert_, _Stannis_, _Renly_. As a result, the editor should print:

<pre class='hexlet-basics-output'>
RobertStannisRenly
</pre>

Use a `print_r()` call for each name.

tips: []
tips:
- |
[A little about interpreters](https://en.wikipedia.org/wiki/Interpreter_(computing))

definitions:
- name: "Instruction"
description: "a command given to computer. PHP code is a set of instructions separated by `;`"
- name: The interpreter
description: |
is a program that runs the code in PHP.
- name: An instruction (statement)
description: |
is a command for a computer written in a programming language. PHP code is a set of instructions separated (most often) by a `;`.
41 changes: 28 additions & 13 deletions modules/10-basics/45-testing/description.en.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
---

name: How do we verify solutions?
name: How we test your solutions
theory: |

Our website verifies your solutions automatically. You may wonder how it works.
Our site automatically checks your solutions. You may be wondering how it works.

In the simplest case the system runs your code and analyzes the screen output. Then it compares the actual output against the expected output.
In the simplest case, the system just runs the code and looks at what's displayed on the screen. Then it compares the actual output against the expected one.

The following lessons deal with more complex matters. You will be writing functions: a kind of mini-programs that receive some data from outside and perform operations on it. Verifying solutions gets a little more complicated in that case. The system runs your code sending some data to it. The system knows what result a correctly written function would receive with that particular data and "expects" it.
In the future, more complicated lessons, you will write functions - mini-programs that take information from the external world and perform operations on it. Verifying solutions gets a little more complicated in this case. The system runs your code and passes data to it. The system knows what result a correctly written function would give with the data the system provides it with, and this result is what the system expects.

Let's assume your task is to program a function that adds two numbers. The verification system would give it several combinations of numbers and compare your function's answers with correctly calculated ones. If all actual values match the expected ones, your solution would be considered valid.
Let's assume your task is to program a function that adds two numbers together. The checking system will give it several combinations of numbers and compare your function's answers with the correct answers. If all actual values match the expected ones, your solution will be considered valid.

This approach is named testing. It is used extensively in the real life day-to-day development process. A developer usually writes tests _first_, and only after proceeds to writing the program itself. During that process he runs tests multiple times to check how close he got to the desired solution.
This is testing. It's used extensively in the real, day-to-day development process. Developers usually write the tests first, and only after that do they actually proceed to write the program itself. During that process, they run tests multiple times to check how close they are to the desired solution.

That is why our website says, “Tests passed” once you've done the exercise correctly.

That is why our website says “Tests passed” once you solved the task correctly.
Here's a simple example, say you want to print the string `Hello, World!`. Now imagine you make a small mistake and the function displays a different value. In that case, the system will give you the following message:

One of your tasks in the following lessons will be to write a function that performs certain calculations and returns the result. As an example, let's assume you made a small mistake and the function returned a wrong value. In that case, the system will give you the following message:
<pre class='hexlet-basics-output'>
-'Hello, World!'
+'ello, World!'

<pre class='hexlet-basics-output'>Fatal error: Uncaught Assert\InvalidArgumentException: Value "10" does not equal expected value "35".</pre>
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
</pre>

A hint appears on the screen. The `+` sign on it indicates what your code printed. The `-` sign is what was expected. By comparing the two values, you can see the error. In the example above, you can see that the letter _H_ is missing from the output.

In addition to our tests, it'll also be extremely useful to experiment with code. To do this, you can use [repl.it](https://repl.it/languages/php). Ideally, you should execute all the code in the lessons yourself.

---

Sometimes, it'll seem that you've done everything correctly, but the system seems to be fickle and won't make a decision. It's nigh on impossible for the system to just decide that it's wrong. Failed tests simply won't get as far as the site, they're automatically run after each change. In the vast majority of cases (all our projects have been run millions of times in total over many years) the error is in the solution code. It can be very imperceptible, maybe you used the wrong punctuation, or you used upper case instead of lower case, or you missed a comma. Other cases are more complicated. Maybe your solution works for one set of inputs, but not for another. So always read the instructions and test your output carefully. There will almost certainly be a sign of an error.

However, if you're sure there's an error or find some kind of inaccuracy, you can always point it out. At the end of each theory section, there's a link to the contents of the lesson on Github (this project is completely open-source!). You can write about an issue, look through the tests (you can see how your code is called there), and even send a pull request. If this still feels like a dark forest for you, then join our community, we'll always be there to help in the _#hexlet-feedback_ channel.

The main thing comes after the colon: “Value ‘10’ does not equal expected value ‘35’”. This means the correctly designed function would have returned 35, and yet the current function returns 10 — which means it works incorrectly.

instructions: |
Print the following to screen: `9780262531962`.
Display `9780262531962`.

definitions:
- name: Tests
description: "code designed to check if a program works correctly; it does so by comparing a set of known valid results against the actual output of the program."
description: |
are special code that checks the programs have been made correctly by checking the correct result against the actual one.

tips:
- |
[assert](https://php.net/manual/en/function.assert.php)
[TDD](https://en.wikipedia.org/wiki/Test-driven_development)
24 changes: 14 additions & 10 deletions modules/10-basics/50-syntax-errors/description.en.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
---

name: Syntax errors
name: Syntax errors
theory: |
If a PHP program isn't syntactically correct, the interpreter will show a relevant message and point you to the file and the line where the error has possibly occured. **Syntax errors** occur when the code has grammar mistakes. Grammar rules are important in human languages, grammar mistakes won't affect your ability to read or understand any text. In programming, however, we must follow rules to the letter. Even a tiny mistake can halt your program. A wrong parenthesis order, forgetting to add a semicolon `;` — these are just few examples of such mistakes.

Here is an example of code with a syntax error:
If a PHP program is written syntactically incorrectly, the interpreter will display a corresponding message on the screen, along with a pointer to the file and line where it thinks the error occurred. _Syntax errors_ occur when the code has grammatical mistakes. Grammar is essential to human language, but a text with grammar mistakes can still be read and understood. However, when it comes to programming, things are much more strict. Any tiny violation and the program won't even start. Maybe you've mixed up your brackets, or there's a `;`, that you forgot to add — these are just some examples of such mistakes.

Here is an example of some code with a syntax error:

```php
<?php

print_r('Hodor')
```

If we run this code we will see the following message: `$ PHP Parse error: syntax error, unexpected end of file in /private/var/tmp/index.php on line 4`. In PHP such errors are called "Parse error". As we can see it includes a file path and a line number.
If you run the code above, you'll see the following message: `$ PHP Parse error: syntax error, unexpected end of file in /private/var/tmp/index.php on line 4`. These syntax errors in PHP are classified as "Parse errors". As you can see, the path to the file and the line number are given at the end.

On one hand, parse errors are the simplest because they are all about code grammar rules and aren't related to any code logic. They can be easily fixed, you just need to find where the syntax is incorrect.
On the one hand, "Parse error" errors are the simplest, because they're ony related to the grammatical rules of code writing, and not to the meaning of the code itself. You can easily fix it once you find it.

On the other hand, the interpreter will not always tell you the exact location of an error. Sometimes you need to add a missed bracket to another place as opposed to what the error message says.
On the other hand, the interpreter won't always tell you the correct position of an error. Sometimes you need to add a forgotten bracket to a different place than where the error message says.

instructions: |
Print to screen the following phrase: `What Is Dead May Never Die`.

This task isn't directly related to the lesson, but it would be useful to practice with printing anyway.

Print `What Is Dead May Never Die`.

tips: []

definitions:
- name: "Syntax error"
description: "violation of grammar rules in a programming language"
- name: "Syntax errors"
description: "are a violation of the grammatical rules of a programming language."
- name: "Parse error"
description: "type of errors in PHP caused by syntax errors in the code"
description: "is a type of PHP error that occurs when there are syntax errors in the code."
8 changes: 4 additions & 4 deletions modules/10-basics/description.en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Basics
description: |

Learning to program is a hard and a long process. And it's not limited to the syntax of a language. We would say that learning syntax is the easiest and the shortest step on the path, but we can't skip it. This Basics module is devoted to the basics of writing programs in PHP. It will serve as the basis for writing more complex programs later.
name: PHP Basics
description:
PHP is one of the most popular programming languages in the world. More than 80% of websites on the Internet are written in this language.

We'll learn PHP from scratch, starting from the very basics. The first module is a springboard for writing meaningful programs. In it, we'll show you how to write your first code in PHP. We'll tell you what comments are and why they're needed. We'll also look at testing by checking your solutions as an example.