PHP Keywords: namespace

Welcome to my series on every PHP keyword and its usage. Today’s item: namespace. The problem Every time you define a class, function or constant in the global scope, you define one more name that you can’t use again. This is typically fine in your own code, it’s easy enough to come up with a different name, if you’ve already used one before. But what about when you want to use someone else’s library?

PHP Keywords: instanceof

Welcome to my series on every PHP keyword and its usage. Today’s item: instanceof. The instanceof operator allows you to check if an object is an instance of a particular class (or a class that extends a particular class) or implements a particular interface. Most of the time you’ll directly check if an object implements a specific class, but you can also check it against a class name stored inside a variable.

PHP Keywords: goto

Welcome to my series on every PHP keyword and its usage. Today’s item: goto. The goto statement allows you to jump around in the current context, disregarding normal code flow. Using goto should be avoided in most situations, as it makes it harder to reason about your code. In PHP, goto is restricted to the current file, and the current context. This means that you can not jump to another file, nor can you jump into or out of a function.

PHP Keywords: do, while and endwhile

Welcome to my series on every PHP keyword and its usage. Today’s items: do, while and endwhile. The while loop is the simplest loop to use, and the easiest to mess up and trigger an infinite loop, since it does not encourage you to iteratively change the condition. Here’s a quick example: 1 2 3 4 5 6 7 <?php $i = 0; while($i < 10) { echo $i; } As you can see, we’ve forgotten to increment $i, causing an infinite loop.

PHP Keywords: private, protected and public

Welcome to my series on every PHP keyword and its usage. Today’s items: private, protected and public. These keywords are collectively known as visibility, and describe where a class constant, property or method can be accessed from. A private constant, property or method can only be accessed from within the class that defines it. A protected constant, property or method can only be accessed from within the class that defines it, or a descendant of that class.