Skip to content

Tag: oop

PHP Interfaces, Traits, and Inheritance, how and when to use them

Hi all So this one is going to be fairly short and simple, I hope! What I am going to cover, and this does assume so prior knowledge, is what interfaces, traits, and inheritance are; and some different use cases for them. So the first one, and maybe the easiest one to cover, first: Inheritance In its simplest term, and I’m going to try and keep things simple in this article. In very brief terms, inheritance is about extending something which exists. Of course, you may well have created this base on which you’re extending. Simple use case: User class,…

Leave a Comment

Quick Life Hacks with the Eloquent Model

Hi folks, It’s no secret that I love Laravel, and especially love Eloquent. This post isn’t about why various people don’t like Eloquent, etc, etc. but just some “life hacks” of working with Eloquent. #1 – Naming Conventions I personally like to use the following naming convention on my databases (using a forum as an example) forums forums_topics forums_topics_replies Whereas Eloquent would expect the following: forums forum_topics forum_topic_replies I personally dislike this, for no other reason than I like to be able to see what’s being owned by what at a very quick glance. Additionally, namespacing; I like to namespace…

Leave a Comment

Quick and Easy PHP Singleton

Hi guys A really short one today, just because someone asked me about it a couple of days ago. I also though it potentially best to avoid something as controversial as my last post about Eloquent and the Single Responsibility Principle, which caused a bit of a stir during the week. So, you want to make sure you only ever use one specific instance of a class (maybe a DB connection) and need a quick and easy way to do it. Personally, this is the technique I would use: <?php class MySingleton{ // This will hold the instance of the…


Some quick translations, OO PHP to C#

So a recent project has facilitated me brushing up on my C# – so I thought I would share some basic translations of things that can be frustrating when you know the usual programming principles (object orientated programming), but not all the syntax. A quick couple of points to note: C# is a strictly typed language, that means you have to know about what your variables are going to be, and yes, you have to declare them somewhere sensible Accessing methods and properties within your class does not require usage of $this – you’re talking about true scope of variables…

Leave a Comment