Image for post
Image for post

Using references in PHP can be sometimes confusing especially if you don’t exactly understand their purpose. Let’s take a look at $this, self and static references using simple examples to explain their usage in an easy to understand way.

$this

Let’s start by taking a look at the following example:

Executing the script above will result in echoing:

0
1

There’s no doubt about it since $this always refers to the instance itself on which the method is called (or the attribute accessed).

Since there’s no multiple inheritance in PHP (yet) you can imagine it simply as a queue of…


Image for post
Image for post

Have you been using XAMPP for a while and every time you want to access your project you’ll do one of the following:

  • used the default URL and went to the directory of your project like localhost/my-project-folder
  • changed Apaches httpd.conf file by editing the DocumentRoot and Directory to match your project folder

If that’s you’re case then you’re in luck ‘cuz there’s a more sophisticated way of doing so that’ll let you have as many domain aliases for all your projects as you’ll need just in four steps.

1. Setting up a local alias for our new domain

First you’ll need to set up a new entry in the hosts…

Michal Tuček

PHP developer | University student | Tutor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store