Created
August 7, 2017 06:15
-
-
Save rajvanshipradeep15/70c7fc1f57fdf77136db282b628f9ec2 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// your code goes here | |
class Example { | |
private $search; | |
public function __construct ($search) { | |
$this->search = $search; | |
} | |
public function setSearch ($search) { | |
$this->search = $search; | |
} | |
public function getReplacer ($replacement) { | |
echo "\n"; | |
echo "im inside getReplacer: ". $replacement; | |
return function ($text) use ($replacement) { | |
echo "\n"; | |
echo "text: " . $text; | |
echo "\n"; | |
return str_replace ($this->search, $replacement, $text); | |
}; | |
} | |
} | |
$example = new Example ('hello'); | |
$replacer = $example->getReplacer ('goodbye'); | |
//print_r( $replacer ); | |
echo "\n"; | |
echo $replacer ('hello world'); // goodbye world | |
$example->setSearch ('world'); | |
echo "\n"; | |
echo $replacer ('hello world'); // hello goodbye | |
$replacer = $example->getReplacer ('pradeep'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment