Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function key-exists: The first argument should be either a string or an integer #7

Open
NabiKAZ opened this issue Dec 28, 2014 · 0 comments

Comments

@NabiKAZ
Copy link
Contributor

NabiKAZ commented Dec 28, 2014

Hi,
If open site for first time and didn't set any cookie and session, and also if didn't set any Accept-Language for browser. When open site show this error in debug mode:

PHP warning
key_exists() [function.key-exists]: The first argument should be either a string or an integer
...\protected\modules\translate\components\MPTranslate.php(201)

188         function getLanguage(){
189         $key=self::ID;
190         if(($language=@$this->_cache['language'])!==null)
191             return $language;
192         elseif(Yii::app()->getSession()->contains($key))
193             $language=Yii::app()->getSession()->get($key);
194         elseif(isset($_POST[$key]) && !empty($_POST[$key]))
195             $language=$_POST[$key];
196         elseif(isset($_GET[$key]) && !empty($_GET[$key]))
197             $language=$_GET[$key];
198         else
199             $language=Yii::app()->getRequest()->getPreferredLanguage();
200         
201         if(!key_exists($language,$this->acceptedLanguages)){
202             if($language===Yii::app()->sourceLanguage)
203                 $language=$this->defaultLanguage;
204             elseif(strpos($language,"_")!==false){
205                 $language=substr($language,0,2);
206                 if(!key_exists($language,$this->acceptedLanguages))
207                     $language=$this->defaultLanguage;
208             }
209         }
210         return $language;
211     }

And in no debug mode:

CException
Property "CAttributeCollection.name" is not defined.

This bug is critical, because some bot didn't set Accept-Language in header request, for example I have problem with google crawler for fetch site.

You can test it with CURL without any parameter for headers:
curl www.sitename.com

I resolve this bug for put @ sign before if(!key_exists in line 201, 206 in above code.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant