Created
January 13, 2015 15:18
-
-
Save vlakoff/7d6122564a0ec41d7e80 to your computer and use it in GitHub Desktop.
Stringy - Create extended Stringy from existing instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require './vendor/autoload.php'; | |
use Stringy\Stringy; | |
class MyStringy extends Stringy { | |
// http://php.net/manual/en/language.oop5.visibility.php#language.oop5.visibility-other-objects | |
// Objects of the same type will have access to each others private | |
// and protected members even though they are not the same instances. | |
// This is because the implementation specific details are already | |
// known when inside those objects. | |
public static function createFromInstance(Stringy $stringy) | |
{ | |
return new static($stringy->str, $stringy->encoding); | |
} | |
} | |
$stringy = new Stringy('ééé', 'UTF-8'); | |
$myStringy = MyStringy::createFromInstance($stringy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment