PHP Clone and Shallow vs Deep Copying

Looking through the PHPExcel library recently I saw how Mark Baker overrides the magic __clone method with comments about ensuring that cloning will perform a deep copy instead of a shallow one. This is a topic with which I had not had much experience so I did some research and experimenting to learn what happens when you use clone and the difference between a shallow copy and a deep copy.

Implementing OOP

Back in June 2014 I gave a presentation to devICT about how to use Object Oriented Programming in PHP and Ruby. I chose this topic when I was explaining inheritance to a friend and realized others would be interested. I chose PHP and Ruby for examples because I was already familiar with OOP in PHP and I wanted to learn more about Ruby’s object model.