Skip to content

Instantly share code, notes, and snippets.

@muathendirangu
muathendirangu / trycatchphp
Created March 3, 2024 19:20
gist that shows how to use try-catch block to handle errors in PH
<?php
try {
// Open the file for reading
$file = fopen("myfile.txt", "r");
// Check if the file was opened successfully
if ($file) {
// Read the content of the file
$content = fread($file, filesize("myfile.txt"));
echo "File content: " . $content;
@muathendirangu
muathendirangu / phpclass
Last active March 3, 2024 19:18
define a class and create objects in PHP
<?php
class Car {
// Public properties (accessible from anywhere)
public $brand;
public $model;
// Private property (accessible only within the class)
private $color;
// Constructor (optional)