Skip to content

Instantly share code, notes, and snippets.

@vlakoff
Created January 13, 2015 15:18
Show Gist options
  • Save vlakoff/7d6122564a0ec41d7e80 to your computer and use it in GitHub Desktop.
Save vlakoff/7d6122564a0ec41d7e80 to your computer and use it in GitHub Desktop.
Stringy - Create extended Stringy from existing instance
<?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