Compilation failed: unrecognized character after (?

This might be a bit random for people but I'm using CakePHP (cakephp.org) and CakeAMFPHP which is Cake's version of the open source flash remoting project AMFPHP (amfphp.org).

The error I'm getting is

Compilation failed: unrecognized character after (?

the line of code is

elseif (preg_match('/(?P<direction>\\x20ASC|\\x20DESC)/i', $keys, $match))

from

function order ($keys, $direction = 'ASC')
    {
        if (empty($keys))
        {
            return '';
        }
        if(is_array($keys))
        {
            foreach($keys as $key => $value)
            {
                if(is_numeric($key))
                {
                    $key = $value;
                    $value = ' '.$direction;
                }
                else
                {
                    $value= ' '.$value;
                }
                $order[] = $this->name($key).$value;
            }
            return ' ORDER BY '.join(',', $order);
        }
        else
        {
            $keys = preg_replace('/ORDER\\x20BY/i', '', $keys);
            if (strpos('.', $keys))
            {
                preg_match_all('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', $keys, $result, PREG_PATTERN_ORDER);
                $pregCount = count($result[0]);

                for ($i = 0; $i < $pregCount; $i++)
                {
                    $keys = preg_replace('/'.$result[0][$i].'/', $this->name($result[0][$i]), $keys);
                }
                if (preg_match('/\\x20ASC|\\x20DESC/i', $keys))
                {
                    return ' ORDER BY '.$keys;
                }
                else
                {
                    return ' ORDER BY '.$keys.' '.$direction;;
                }
            }
            elseif (preg_match('/(?P<direction>\\x20ASC|\\x20DESC)/i', $keys, $match))
            {
                $direction = $match['direction'];
                $keys = preg_replace('/'.$match['direction'].'/', '', $keys);
                return ' ORDER BY '.$keys.$direction;
            }
            else
            {
                $direction = ' '.$direction;
            }
            return ' ORDER BY '.$keys.$direction;
        }
    }

the Cake file is /cake/libs/model/datasources/dbo_source.php.

thanks
LVL 1
vixiomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomeeboyCommented:
Not sure if you can have parenthesis in the regex like that.. hm.. Try this:

elseif (preg_match('/\(?P<direction>\\x20ASC|\\x20DESC\)/i', $keys, $match))
0
TomeeboyCommented:
Err.. sorry, memory lapse there.  I think it's considering (?P to be a regex option, but not completely sure (I'm not the greatest with regex).  If so, then "P" is not being recognized as a valid attribute for that option I guess.
0
TomeeboyCommented:
Okay, beginning to understand the expression a bit more after doing some further digging.  ?P<direction> is attempting to create a backreference "direction" for the capture group (which is defined by the parentheses).  Did you put that regex in there yourself?  Unfortunately, I'm nowhere near good enough with regex to know if that is even supported in PHP (or if there's another way to do it that won't cause an error).  Maybe one of the regex gurus could chime in on this one?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

vixiomAuthor Commented:
I didn't write any of this, it's a part of the Cake framework, a very specialized part to use AMFPHP. I'm a Flash guy and AMFPHP is how I use Flash remoting with PHP/MySQL, I'm just trying to get the Cake framework going with remoting cause it's going to save me tons of time building apps.

So... long story short I'm most likely worse at regex than you are :)

It's an alpha build of CakeAMFPHP so I've reported the error I just wanted to see if I could fix it.
0
TomeeboyCommented:
Heh.  Well, I haven't personally seen that method of backreferencing used in a PHP regex, but that doesn't mean much :)  You could try replacing that elseif statement with this:

elseif (preg_match('/\\x20ASC|\\x20DESC/i', $keys, $match))
            {
                $direction = $match[0];
                $keys = preg_replace('/'.$match[0].'/', '', $keys);
                return ' ORDER BY '.$keys.$direction;
            }

preg_match stops at the first match it finds, and if a 3rd parameter is specified in the function call ($match in this case), it returns the match in the form of an array.  $match[0] is the text that matched the full pattern.  I don't think the above would work any differently than what you originally had (other than the fact that it might actually WORK).  Try it and see if there's any difference :)
0
WaielEidCommented:
i checked the source files and truly i didn't see that error there

the function in the files was this

    function order ($keys, $direction = 'ASC')
    {
        if (empty($keys))
        {
            return '';
        }
        if(is_array($keys))
        {
            foreach($keys as $key => $value)
            {
                if(is_numeric($key))
                {
                    $key = $value;
                    $value = ' '.$direction;
                }
                else
                {
                    $value= ' '.$value;
                }
                $order[] = $this->name($key).$value;
            }
            return ' ORDER BY '.join(',', $order);
        }
        else
        {
            $keys = preg_replace('/ORDER\\x20BY/i', '', $keys);
            if (strpos('.', $keys))
            {
                preg_match_all('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', $keys, $result, PREG_PATTERN_ORDER);
                $pregCount = count($result['0']);

                for ($i = 0; $i < $pregCount; $i++)
                {
                    $keys = preg_replace('/'.$result['0'][$i].'/', $this->name($result['0'][$i]), $keys);
                }
                if (preg_match('/\\x20ASC|\\x20DESC/i', $keys))
                {
                    return ' ORDER BY '.$keys;
                }
                else
                {
                    return ' ORDER BY '.$keys.' '.$direction;;
                }
            }
            elseif (preg_match('/(\\x20ASC|\\x20DESC)/i', $keys, $match))
            {
                $direction = $match['1'];
                $keys = preg_replace('/'.$match['1'].'/', '', $keys);
                return ' ORDER BY '.$keys.$direction;
            }
            else
            {
                $direction = ' '.$direction;
            }
            return ' ORDER BY '.$keys.$direction;
        }
    }

as you can see the state ment is

        elseif (preg_match('/(\\x20ASC|\\x20DESC)/i', $keys, $match))
            {
                $direction = $match['1'];
                $keys = preg_replace('/'.$match['1'].'/', '', $keys);
                return ' ORDER BY '.$keys.$direction;
            }
not the one you posted
there is no P<direction> in it

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vixiomAuthor Commented:
Getting the latest source fixed it. Doh! I was using an earlier version of cake.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.