Skip to content

Instantly share code, notes, and snippets.

@sanglt
Created October 24, 2012 03:23
Show Gist options
  • Select an option

  • Save sanglt/3943490 to your computer and use it in GitHub Desktop.

Select an option

Save sanglt/3943490 to your computer and use it in GitHub Desktop.
<?php
// Class String
class String {
// protected variable
protected $_string;
// public variable
public $string;
// Assign string to public variable
public function __construct($string) {
$this->string = $string;
}
// Assign string to protected variable
public function setValue($string) {
$this->_string = $string;
}
/**
* get CleanUp object
* @return \CleanUp
*/
public function getCleanUp() {
return new CleanUp($this);
}
}
// Class CleanUp
class CleanUp extends String {
protected $_object;
public function __construct($object) {
$this->_object = $object;
}
public function doAction() {
// Clean this object
$vars = get_object_vars($this->_object);
return $vars;
}
}
$stringObj = new String('Andy 123');
$stringObj->setValue('Andy protected');
print_r($stringObj->getCleanup()->doAction());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment