Cultivating Miniature Worlds through Sub-Namespace If you can define namespaces, then it’s no different to define sub-namespaces. We’re also going to look at classes with the same name from different sub-namespaces and how we’re going to handle those naming conflicts that still might arise. Recap: Review where we left off last time. The only difference is that we changed the namespace from CoolCars to Vehicles. https://blog.devgenius.io/php-p69-defining-namespaces-5a8e0a4bfdc0 https://github.com/dinocajic/php-youtube-tutorials/tree/master If we start with our Car class, we can see that it belongs to the Vehicles namespace. <?php namespace Vehicles; require_once(‘Vehicle.php’); require_once(‘Engine.php’); require_once(‘Transmission.php’); class Car extends Vehicle { //… } What we want is for
Tag: PHP Namespaces
Dividing and Conquering through Namespace Architecture Defining namespaces is pretty simple. At the top of the file, right after the opening PHP tag, the namespace keyword is used, followed by the virtual directory of your choosing. This virtual directory can act as a single directory, or be few sub-directories deep. We’re also going to be looking at using the use keyword. Remember the use keyword? Yeah, well it’s coming back. Recap: Review the previous article and code. We’ll be building off of our previous code. https://github.com/dinocajic/php-youtube-tutorials/tree/master https://blog.devgenius.io/php-p67-parent-constructor-ec8e41b9a6a9 Let’s start off by creating our test file. <?php // Defining Namespaces require_once(“Lamborghini.php”); $lamborghini
Just a virtual directory trick Namespaces are used throughout numerous programming languages. If you’re familiar with Java, you might have heard of the term package. A package is a namespace in Java. The package allows the developer to group similar code together. In the simplest sense, a package is a folder or a directory. https://blog.devgenius.io/php-p67-parent-constructor-ec8e41b9a6a9 Namespaces give the programmer the ability to reuse class names in different contexts. The easiest way to look at namespaces from a non-programming perspective is through the convention on how people are named. My parents gave me the first name Dino. Although there are probably