Setup VS Code for PHP

  1. Install VS COde
  2. Install or copy PHP executable https://www.php.net/downloads
  3. Add some Json files in Settings of VS code. (navigate to File -> Preferences -> Settings)
  4. Click on “Open Json settings button on top right side icon” It will open settings.json file
  5. Paste following code block in it, correct the runtime execuatable file path accordingly.
{
    "launch": {
        "configurations": [
            {
            "type": "php",
            "request": "launch",
            "name": "Run using local PHP Interpreter",
            "program": "${file}",
            "runtimeExecutable": "C:\\php\\php.exe"
            }],
        }
    
}

6. Now install the extension, go to the extension tab in VS Code and search “PHP” install PHP Debug by Felix Becker, Now VS code is ready to execute PHP in VS Code.

Note: if you don’t want to use VS Code to run PHP code, you can also use online editor Implode https://implode.io/

Reset MySQL Root/Admin/AnyUser forgoten password using SSH

Stop MySQL

#For Ubuntu or Debian
sudo /etc/init.d/mysql stop

#For CentOS, Fedora, and RHEL
sudo /etc/init.d/mysqld stop

Start MySQL in safe mode
start MySQL but skip the user privileges table, you will need to have sudo access for these commands so you don’t need to worry about any user being able to reset the MySQL root password:

sudo mysqld_safe --skip-grant-tables &
#ampersand (&) at the end of the command is required.

Login MySQL
No password is required at this stage as when we started MySQL we skipped the user privileges table

mysql> mysql -u root

Tell MySQL which database to use

mysql> use mysql;

Check list of users from user

mysql> select User, Password from user;

Reset Password

mysql> update user set password=PASSWORD("mynewpassword") where User='root';

Flush the privileges

mysql> flush privileges;

Exit MySQL

mysql> quit

Stop and start MySQL

#On Ubuntu and Debian:
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

#On CentOS and Fedora and RHEL:
sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start

Login with new Password

mysql -u root -p

Motivation behind using Object Oriented Programming (OOP)

Simplicity
One important way to deal with complexity is to reduce it to something simpler.
Divide and conquer principle: Divide the original problem into separate sub-problems that can be solved individually.

Maintainability
We must also be able to maintain and extend the solution in an evolving world. So it is important that the use OOP not only solve the problem, but also result in a program that can be maintained.

Reusability
When you divide problems into sub-problems, you will sometimes see similar sub-problems. Then it would be nicer to reuse a similar solution.

Flexibility
It is also desirable that your software is flexible. You may for example need to deliver several variants of your software to different customers.
Or you may need to reconfigure the software to a changed context. Also some of your shared sub-solutions may need to go into contexts that are not completely the same.

Difference between Class and Object

Class vs Object
A class is a Blue print of an object. a general concept (like an Animal), an object is a very specific embodiment of that class, with a limited lifespan (like a lion, cat, or a zebra).

Class

  1. Definition: Class is mechanism of binding data members and associated methods in a single unit.
  2. Existence: It is logical existence
  3. Lifespan: Classes do not have a lifespan
  4. Memory Allocation: Memory space is not allocated , when it is created.
  5. Declaration/Definition: Definition is created once.

Object

  1. Definition: Instance of class or variable of class.
  2. Existence: It is physical existence
  3. Lifespan: Objects have a lifespan
  4. Memory Allocation: Memory space is allocated, when it is created.
  5. Declaration/Definition: it is created many time as you require.

Late Static Bindings (PHP 5.3)

// Limitation of Self:: in PHP 5.2 
// before Late Static Binding PHP 5.3
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        self::who();
    }
}

class B extends A {
    public static function who() {
        echo __CLASS__;
    }
}

B::test(); // This will output: A

// Late Static Binding in PHP 5.3
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        static::who(); // Late Static Bindings
    }
}

class B extends A {
    public static function who() {
        echo __CLASS__;
    }
}

B::test(); // This will output: B