I want to replace all “private function __someMethod()” with “protected function _someMethod().
But I do want to leave the magic ones untouched.
The replacing does not work though.
$x = array(
'/\bprivate function __([^(construct|destruct|sleep|wakeup|get|set|call|toString|invoke|set_state|clone|callStatic|isset|unset)])\b/i',
'protected function _\1'
)
\b and \b as word boundaries.
it uses preg_replace($x[0], $x[1]).
thx!
i also tried [^construct^destruct^sleep] etc
the same applies to " $this->__ " and " ::__ " (static call) then, of course.
The
[^...]syntax is a negated character class. Everything in square brackets is just a list of characters, the()and the|are not interpreted, and your words get shuffled into a list of letters.What you wanted to use was a negative assertion
(?!....)It should be followed by
\w+to work for your preg_replacing.