1

Consider the following function declaration for checking current language on a bilingual website:

function checkNewsLanguage(){
    $requiredURL = $_SERVER['REQUEST_URI'];
    $myLanguage = explode('?lang=',$requiredURL);
    if($myLanguage=='en')
        return false;
    else return true;
}

Then I get some XML objects in the required language using functions like:

function item1('checkNewsLanguage')
    if(checkNewsLanguage()){
        $urlD = "someurl1";
        $xmlD = simplexml_load_file(cacheFetch($urlD,'cachedfeed1.xml',3600));
        $itemD = '';
        if($xmlD === FALSE)
            {$itemD = '';}
        else
            {$itemD = $xmlD->channel->item;}
    }
    else {
        $urlD = "someurl2";
        $xmlD = simplexml_load_file(cacheFetch($urlD,'cachedfeed2.xml',3600));
        $itemD = '';
        if($xmlD === FALSE)
            {$itemD = '';}
        else
            {$itemD = $xmlD->channel->item;}
    }
    return $itemD;
    }
function item2('checkNewsLanguage')
//Analogic procedure

I get "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE ". As you see the function calls in item1() and item2() are not correct. Any code help is greatly appreciated.

2 Answers 2

2

Your function arguments need to be a variable, not just a string (as the error suggests). Your functions should be defined like:

function item1($variableHere) and not function item2('string here').

As I look at your code again, it seems what you are trying to do is call a certain function based on the parameter of item1() and item2() (so if you pass item1(foo) you want to call the foo() function.

Try:

function item1($function)
{
    if ($function()) 
    { 
        ...
    }
}

and similar for item2(). This way you can call item1('checkNewsLanguage') and that is the function it will call inside of the body.

Sign up to request clarification or add additional context in comments.

Comments

1

The problem is on line:

function item1('checkNewsLanguage')

You can't have 'checkNewsLanguage' in the paranthesis there. You need to have a variable that accepts the function argument.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.