Posts

Showing posts from 2020

DEBUGGING

HOW TO DEBUG CODE IN PHP What is debugging in PHP? Where does this strange name come from, and what is this really about? Term debugging is well known to all developers – not only PHP ones. It is a common term for trying to fix the wrongly working script. I don’t want to examine why we call a software error a bug. If you are curious about the origins, check out this link. Debugging is simply getting rid of errors from the software. When you write the code, it often turns out that something doesn’t work as planned. It’s worth knowing how to deal with such problems. You don’t always know where the mistake is made. Sometimes these are trivial errors like missing semicolon at the end of the command or some typo in the name of the method. The better the editor for writing the code, the faster we will catch those trivial errors. Smarter editors even highlight errors immediately, underlining the syntax and suggest proper names. Check out recommended text editor in the PHP development environm...

COMMENTS

COMMENTS A few words about the comments. Comments are used, as the name suggests, for commenting sections of code. With their help you can efficiently document the created code and enable quick preview of documentation for other developers. Wait.. What? What does it mean to document the code? Let’s say that documentation of the code is just providing some tips for other developers of how your application is written. No worries, we’ll get to that later. The most important thing for you at this point is that the added comment is ignored by the PHP interpreter. It means you can leave a note that will not be displayed on the page and no one will be able to see it in the browser. WHY YOU USE COMMENTS? The principle is simple – let’s comment anything that can be difficult to understand after some time. Generally, well-written code does not require a lot of commenting. Especially, you shouldn’t comment such things as variable’s name or why you multiply some values. The names of variables, fun...

PHP OPERATORS

PHP OPERATORS You’ve just learned how variables and constants work. Now it’s time for operators. With use of operators you can influence variables and their values. Just see the full list here. ARITHMETIC OPERATORS The first category of PHP operators that I wanted to introduce here are arithmetic operators. Their use is very intuitive and the operation result almost obvious. It all about addition, subtraction, multiplication and division of numbers. In addition to this group the operator returns the remainder of the division. The list looks as follows: “+” returns the sum of two numbers or strings, “-” returns the difference, “*” returns the multiplication, “/” returns the division, “%” returns the remainder of division. COMPARISONS The second category is comparison operators. PHP allows us to check whether two variables are equal or (if they’re not, which one is greater and which is smaller. The comparison operators are: “==” checks if two variables are equal in value, “! =” checks if...

VARIABLES AND CONSTANTS

VARIABLES AND CONSTANTS As in many other programming language, also in PHP we deal with variables and constants. What are they and what will we use them for when writing scripts? As you’ve already done the first exercise with writing first line of code, you are ready to learn further. VARIABLES Variable in PHP is a container that stores a certain value. It doesn’t matter if it’s boolean, integer, rational or text. An interesting fact in PHP is that there is no need to declare a variable or its type, which may be required in other popular languages (like C# or Java). This means that you can use a certain variable even if you haven’t yet created it. In addition, PHP itself selects the appropriate data type for the variable. As I said, boolean values, floating point numbers, integers, strings are just examples of the data types. The interpreter underneath chooses the right type for us, based on the assigned value. Fortunately, you don’t have to worry about that. Even if the variable origi...

FIRST LINE OF CODE IN PHP

FIRST LINE OF CODE IN PHP The very first line of PHP code is coming your way. When the PHP environment is ready we can start writing our first script. First of all, congratulations! Hardest part is already behind you. Now you can expect a ton of fun and challenges that will reward you greatly if you persevere. As in any other topic, beginnings are tough. The more you enjoy learning by practice, the easier it gets along the way. We start from creating a new file, which we will be named test.php. An important notice regarding modern code editors (such as VS Code). They work in the context of a folder, hence you don’t need to worry about complicated project creation process inside the tool. Simply, create new empty folder on your harddrive and you are ready to go. Just select it as the project folder inside VS Code (or any other editor – check out recommendations on Resources page). Inside it, create a new file test.php. FIRST CODE IN PHP First, let’s write several lines of classic HTML c...

INSTALLING PHP DEVELOPMENT ENVIRONMENT

PHP DEVELOPMENT ENVIRONMENT INSTALLING NECESSARY TOOLS All scripts written in PHP are executed on the server side. User ’s web browser receives only the HTML code that is a result of processing PHP code by PHP interpreter. It’s easy to guess that without such a server containing a PHP interpreter, we can not do nothing. Luckily for us, over the years there has been published a lot of ready-made packages that makes installing development environment for PHP a lot easier. It’s enough to install one piece of software and we are ready to go. The IT world changes very intensively. You may find it that recommended applications today will be abandoned in a year from now, leaving the space for another better solution. Something much better can appear and displace underdeveloped projects. At the time of writing this article, I will recommend one solution to you. However, try to check at Resources Page to verify that nothing better appeared. There you will always find the appropriate tools for P...

SIMPLE PHP

PHP BASIC COURSE  Free PHP basics course available to everyone – free of charge. Please, enjoy and share if you liked it. CHAPTER ONE: 1. Installing the PHP development environment.  This lesson shows you how to install and run a PHP server and how to pick a code editor for further use. 2. First line of code in PHP.  In this one, you create a new project, first PHP file and write the very first line of code in PHP. 3. Variables and constants.  This is where the development starts. A good understanding of this concept is crucial for fluent programming. 4. Operators.  Now that you know variables and constants, it’s time to become familiar with operators. This is how you can manipulate values and check conditions. 5. Comments.  Learn how to document your work with comments. You can use them also to exclude parts of the code from execution. 6. Debugging.  Since you write some code, learn how to check how it works. It’s all about finding out why code isn’t ...