SolveItproblems

SolveITProblems is a project of QFormat.net intellectual club

SolveITProblems это проект интеллектуального клуба QFormat.net

четверг, 6 мая 2010 г.

PHP Object to String

Stupid problem i faced today, i need to change one web-sites hosting, all steps i'd done but it didn't work:

Warning: preg_match() expects parameter 2 to be string, object given in /home/oscarres/public_html/class/class.session.php on line 32

Catchable fatal error: Object of class language_set could not be converted to string in /home/oscarres/public_html/class/class.session.php on line 38


At first i want to say that if you want to change hosting and you have a web-site builded with some CMS and/or you have very many directories and files and/or use unicode symbols in filename so it will be better not to use just ftp copying, use cpanels backup and restore. backup home directory and mysql database, then go to the phpMyAdmin - export database and after restoring everything at new host, import the database data.

So i've done all this steps and recieved this error. There is no problem with CMS because it works before at other host. i found the place of the error it was the lines of code where programmer saves parameter to the _SESSION['parameter']. it was something like:


_SESSION['language'] = $Row[2]; //readed from the database
...
$lang = _SESSION['language'];
-> and here programmer tried to use preg_match() where the second pasrameter was the $lang and recieves error which inform us that the $lang is not a string! :) . you realize that it became an object when you add it to the session. but nothing you can do :) . google doesnt helped me, even i found how to make type cast from object to string. here i need Java's toString() method.

programming tricks didnt help me and i found solution which was really sily...
from Cpanel i go to the PHP config, and change the version of the PHP from server defined to PHP4 (not PHP5) :) . hope we will never waste 3 hours for searching tricks anymore if the solution is so easy :) ...

1 комментарий:

  1. This is because you're filtering a two dimensional array, an array containing arrays.

    The right regex function for searching an array would be preg_grep(). It returns an array of matches.
    (don't forget to specify the delimiter with preg_quote)

    Sometimes it depend from hosting, thats why I advice to choose best web hosting

    ОтветитьУдалить