Skip to content

Commit

Permalink
php 5.3 self inside closure
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Feb 1, 2018
1 parent df4fde0 commit 1a3872d
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/CssXpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public static function cssToXpath($selector)
$xpath = ' ' . $selector;
$strings = array(); // attribute && :contains() substitutions

$self = $this; // PHP 5.3 workaround for use inside closure

/*
The order in which items are replaced is IMPORTANT!
*/
Expand Down Expand Up @@ -100,10 +98,10 @@ public static function cssToXpath($selector)
$strings[] = '[contains(text(), "'.$matches[1].'")]';
return '[{'.(count($strings)-1).'}]';
}),
array('/([\s]?):not\((.*?)\)/', function ($matches) use (&$strings, $self) {
array('/([\s]?):not\((.*?)\)/', function ($matches) use (&$strings) {
// this currently works for simple :not(.classname)
// unsure of other selectors
$xpathNot = $self::cssToXpath($matches[2]);
$xpathNot = \bdk\CssXpath\CssXpath::cssToXpath($matches[2]);
$xpathNot = preg_replace('#^//\*\[(.+)\]#', '$1', $xpathNot);
$strings[] = ($matches[1] ? '*' : '').'[not('.$xpathNot.')]';
return '[{'.(count($strings)-1).'}]';
Expand Down

0 comments on commit 1a3872d

Please sign in to comment.