---
title: "Discussion on \"PHP cheat sheet (updated to PHP 8.1)\" | Hashnode"
description: "Discussion on \"PHP cheat sheet (updated to PHP 8.1)\". Follow me!: Follow @EricTheCoder_\n\nHere is my cheat sheet I created along my learning journey. If you have any recommendations (addition/subtraction) let me know.\n\nPHP local server\nphp -S localhost:3000\nComments\n// one line comment\n\n/*\nThis is a mult..."
url: "https://hashnode.com/posts/php-cheat-sheet-updated-to-php-81/61c716a91697f253954fe340"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [PHP cheat sheet (updated to PHP 8.1)](https://eric-the-coder.com/php-cheat-sheet-updated-to-php-81?utm_source=hashnode&utm_medium=feed)

Follow me!: Follow @EricTheCoder\_ Here is my cheat sheet I created along my learning journey. If you have any recommendations (addition/subtraction) let me know. PHP local server php -S localhost:3000 Comments // one line comment /\* This is a mult...

Dec 25, 2021 · 9 min read · eric-the-coder.com  
Read the article

-   [#php](https://hashnode.com/tag/php)
-   [#cheatsheet](https://hashnode.com/tag/cheatsheet)

## Written by

[Eric The Coder](https://hashnode.com/@EricTheCoder)

@EricTheCoder · Montreal, Canada

  
[View profile](https://hashnode.com/@EricTheCoder)

My passion is to learn and share

Businessman and blogger. My passion is to learn and share! I work with #React, #Next and #Laravel. I am also a fan of #TailwindCSS

## Responses

Markdown supported · ⌘↵ to post

[Damien Genthial](https://hashnode.com/@dgenthial)

[Mar 11, 2022](https://hashnode.com/posts/php-cheat-sheet-updated-to-php-81/61c716a91697f253954fe340/comment/622afcb2e552e99d82e5a316)

Hello, Very nice cheat sheet, all the must know is there. I picked a little mistake in you file example :

```
//File read
$file = fopen("test.txt", "r");

//Output lines until EOF is reached
while(! feof($file)) {
  $line = fgets($file);
  echo $line. "<br>";
}
fclose($file);
```

In order to detect end of file (and have feof return true), you must read after the last char (or line) in file. So you must read before the test (to detect an empty file) and read at the end of the loop (to avoid echoing an empty line) :

```
//File read
$file = fopen("test.txt", "r");

//Output lines until EOF is reached
$line = fgets($file);
while(! feof($file)) { 
  echo $line. "<br>";
  $line = fgets($file);
}
fclose($file);
```
