Skip to content

Instantly share code, notes, and snippets.

@ZEALi
ZEALi / function.cast.php
Created February 19, 2019 07:31 — forked from borzilleri/function.cast.php
PHP function to cast an object from one class to another.
<?php
/**
* Cast an object into a different class.
*
* Currently this only supports casting DOWN the inheritance chain,
* that is, an object may only be cast into a class if that class
* is a descendant of the object's current class.
*
* This is mostly to avoid potentially losing data by casting across
* incompatable classes.