I have a self explanatory error in my Yii application - I know what the problem is, I would just like to know which line & file this is on.
htmlspecialchars() expects parameter 1 to be string, array given
Can anyone explain the best/easiest way to use the Yii framework to output the exact line number that this error is coming from? I already have some debugging on but it all looks confusing and nowhere does it say Line xxx in file somename.php
You can try this Tutorial :
As you expected, this tutorial showing only file name and line number only.
http://www.yiiframework.com/wiki/113/how-to-customize-error-handling-in-console-mode-applications/
what about using these 2 lines on your index.php??
error_reporting(E_ALL);
ini_set('display_errors', 'on');
Related
I'm a beginner with XML on PHP. My page returns me the following PHP error:
But, at line 2, there only is a "require_once", followed by 3 others "require_once", the path to the required file is ok, and it ends with a ';'. The line above is the "
I have this sample of code, which I think is the source of this error (in this order)
$xml = simplexml_load_string("<result/>");
$entitlements = $xml->addChild("entitlements");
$entitlements->addChild("productId", $productId);
then, below :
$fulfillmentXML = new SimpleXMLElement($result);
//some stuff with $fullfillmentXML
echo $xml->asXML();
I do not understand exactly how the XML works in PHP, but I thought there was a problem creating a SimpleXMLElement() after the simplexml_load_string() call.
Your error doesn't look like a PHP error, but rather a browser error generated when it tried to parse the supplied XML contents. Therefore line 2 of the error does not refer to line 2 of your PHP file, but to line 2 of your generated output.
Check your output (source of your generated page), and see what line 2 is there. Make sure you only have 1 root element, and that nothing comes after it.
I'm trying to get some PHP example code to work on PHP version 5.3.4, Apache 2.2.17 on Windows.
The example says I need PHP 4.0 and above with CURL and contains:
<?
$function = $_GET['function-if-exist'];
$test = "Test";
?>
<? =$test ?>
I don't understand why I'm getting the following errors:
My PHP doesn't understand <? and wants <?PHP instead.
My PHP doesn't like <? =$test ?> and wants something like
<?PHP echo $test ?>
$function = $_GET['function-if-exist']; causes the error "Undefined index" but presumably works for the folks that developed it.
Can anyone help me understand why their code is not working for me?
1) <? is the "short tag". Most servers are configured to not allow short tags. This can be changed in php.ini.
2) Again, short tags. Also I think you can't have a space before the =, but the main problem is the short tags setting.
3) $_GET accesses the query string, so when loading your script you need myscript.php?function-if-exist=something
It is more ideal to check if the parameter is set before continuing to prevent errors being thrown, e.g.
if(isset($_GET['function-if-exist']))
{
$functionexists = $_GET['function-if-exist'];
}
the short tag notation is disabled in your php.ini
you need to remove the space before your equal sign
your _get array contains not the expected index, what url do you enter to access the page?
I don't understand why I'm getting the following errors:
My PHP doesn't understand
To be able to use short tags you will have to enable them via config ... http://www.tomjepson.co.uk/tutorials/35/enabling-short-tags-in-php.html
My PHP doesn't like and wants something like
Once you switch on the short tags you will be able to echo using ... important the equals signs must be touching the ? not variable.
$function = $_GET['function-if-exist']; causes the error "Undefined index" but presumably works for the folks that developed it.
The $_GET is populated according to what is in the url. To get a value in $_GET['function-if-exist'] the url accessing the script should be something like mydemo.php?function-if-exist=hello
Hope this helps you
Quick answers to 1 and 2 are enable the short_open_tag option into the php.ini file, for the last one is set the error_reporting to a less strict mode.
The reasons of not to adopt such measures are:
the short tag clashes with the xml declaration and is disabled on different host, if you need to manipulate xml or if you need to write portable code is better to resort to the long tag syntax. You lose the ability to echoing data with = but it is a small annoyance to me.
Warning and notices, as php forgive a lot the programmer for missing variables declaration are a blessing for debug. Keep then raised and you will address a lot of mispellings.
Are you sure that function-if-exist is a correct index for your hash? I would check the index first the access them. If the index don't exists is a probable hint that something is going wrong with your code and you should check the reason of the missing.
Better to stop now, as anyone can write a book on this topic, and several ones already done ;)
I am trying to store facebook user's data array in mysql. I have used serialize for the conversion of array. When I try to retrieve data, I get absolute blank page. No errors, no output. I have given my code with example below. Please help me to find error.
$arrayString='a:18:{s:2:"id";s:10:"7234123543";s:4:"name";s:18:"John Mc Carthy";s:10:"first_name";s:7:"John";s:11:"middle_name";s:5:"Mc";s:9:"last_name";s:4:"Carthy";s:4:"link";s:35:"http://www.facebook.com/johnmc";s:8:"username";s:11:"johnmc";s:8:"hometown";a:2:{s:2:"id";s:15:"112334563280811";s:4:"name";s:7:"Some city";}s:8:"location";a:2:{s:2:"id";s:15:"112312348780092";s:4:"name";s:16:"Some city, country";}s:6:"quotes";s:234:""All children are artists. The problem is how to remain an artist once you grow up."
- Pablo Picasso
"Boundaries are meant to be broken"
- Malik raza
"Make things as simple as possible but no simpler."
- Albert Einstein";s:20:"inspirational_people";a:6:{i:0;a:2:{s:2:"id";s:15:"109233712349424";s:4:"name";s:10:"Bill Gates";}i:1;a:2:{s:2:"id";s:15:"108103675884224";s:4:"name";s:20:"A. P. J. Abdul Kalam";}i:2;a:2:{s:2:"id";s:15:"104389809597530";s:4:"name";s:13:"Chris Gardner";}i:3;a:2:{s:2:"id";s:11:"11777366210";s:4:"name";s:12:"Paulo Coelho";}i:4;a:2:{s:2:"id";s:11:"68310606562";s:4:"name";s:15:"Mark Zuckerberg";}i:5;a:2:{s:2:"id";s:15:"113529011990795";s:4:"name";s:10:"Steve Jobs";}}s:9:"education";a:2:{i:0;a:4:{s:6:"school";a:2:{s:2:"id";s:15:"110123445652281";s:4:"name";s:5:"college";}s:4:"year";a:2:{s:2:"id";s:15:"144044823450606";s:4:"name";s:4:"2011";}s:13:"concentration";a:1:{i:0;a:2:{s:2:"id";s:15:"192578844099494";s:4:"name";s:16:"Computer Science";}}s:4:"type";s:7:"College";}i:1;a:2:{s:6:"school";a:2:{s:2:"id";s:15:"103122365394699";s:4:"name";s:22:"My School";}s:4:"type";s:11:"High School";}}s:6:"gender";s:4:"male";s:5:"email";s:19:"myemail#gmail.com";s:8:"timezone";d:15.5;s:6:"locale";s:5:"en_US";s:8:"verified";b:1;s:12:"updated_time";s:24:"2011-04-09T21:51:29+0000";}';
$array=unserialize($arrayString);
//echo $array[0];
print_r($array);
Most likely your serialized data is malformed / you've forgotten to escape characters that need escaping. To get php to give you some verbose error report on this turn on error reporting and display errors:
ini_set("error_reporting", E_ALL);
ini_set("display_errors", 1);
"Notice" isn't normally an important enough error message to get displayed, but in this case it will help you debug the problem with your serialization:
Notice: unserialize(): Error at offset 68 of 1720 bytes in file.php on line 7
I have code that works on a handful of servers, but not others which is coming up with serialised data. I call a page like this:
http://domain/index.php/sales/Drilldowns?params=a:12:{s:13:"selectionType";s:8:"facility";s:8:"dateType";s:5:"daily";s:10:"dateOption";s:9:"drilldown";s:6:"metric";s:13:"bookingAmount";s:9:"companyFK";s:2:"11";s:10:"facilityFK";s:0:"";s:7:"classFK";s:0:"";s:15:"customDateStart";s:4:"null";s:7:"newDate";s:10:"2010-11-01";s:10:"metricName";s:10:"Bookings%20$";s:16:"currentDateRange";s:10:"11/01/2010";s:23:"currentMetricNavigation";s:8:"DELDELTE";}&getExcel=0
This is the code I'm using:
protected function getRequestVariables(){
if(isset($_REQUEST['params'])){
var_dump($_REQUEST['params']);
echo 'length:'.strlen($_REQUEST['params']);
$vars = unserialize($_REQUEST['params']);
var_dump($vars);
} else {
$vars = $_REQUEST;
// unset saved drilldown options
$this->ci->session->svar_set('postVars', null);
}
This is a var_dump output:
string(447) "a:12:{s:13:\"selectionType\";s:8:\"facility\";s:8:\"dateType\";s:5:\"daily\";s:10:\"dateOption\";s:9:\"drilldown\";s:6:\"metric\";s:13:\"bookingAmount\";s:9:\"companyFK\";s:2:\"11\";s:10:\"facilityFK\";s:0:\"\";s:7:\"classFK\";s:0:\"\";s:15:\"customDateStart\";s:4:\"null\";s:7:\"newDate\";s:10:\"2010-11-01\";s:10:\"metricName\";s:10:\"Bookings $\";s:16:\"currentDateRange\";s:10:\"11/01/2010\";s:23:\"currentMetricNavigation\";s:8:\"DELDELTE\";}"
When that gets processed I get the following error:
A PHP Error was encountered
Severity: Notice
Message: unserialize() [function.unserialize]: Error at offset 6 of 447 bytes
Filename: plugins/Drilldowns.php
Line Number: 93
I'm trying this on 5.2.13 - works on some Linux, some OS X, not others. Have checked php.ini, charset (I think) - I can't figure it out for the life of me. I've tried things as simple as
string(18) "a:1:{s:3:\"sam\";}" length:18
and it still errors. Any clue as to why?
It's the backslashes in front of the quotes: \"
When you remove them, it works.
var_dump(unserialize('a:12:{s:13:"selectionType";s:8:"facility";s:8:"dateType";s:5:"daily";s:10:"dateOption";s:9:"drilldown";s:6:"metric";s:13:"bookingAmount";s:9:"companyFK";s:2:"11";s:10:"facilityFK";s:0:"";s:7:"classFK";s:0:"";s:15:"customDateStart";s:4:"null";s:7:"newDate";s:10:"2010-11-01";s:10:"metricName";s:10:"Bookings $";s:16:"currentDateRange";s:10:"11/01/2010";s:23:"currentMetricNavigation";s:8:"DELDELTE";}"'));
The servers this works on, probably have magic quotes turned on.
I had this problem and it took me a while to solve it. I just couldn't find any good solution but this is what I did to solve my situation:
base64_encode(serialize($User)); // make sure to encode the serialized object
unserialize(base64_decode($User)); // decode it before unserializing
Just a curious question.
I noticed that when you generate a non fatal php error,
<b>Warning</b>: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in...
but the links are nonsense.
If they are going to link it why do they not link it to the php manual?
or is there someway you can reroute the errors yourself?
There are 3 php.ini settings that control this behaviour
By setting html_errors = 0 no links will be created.
The value of docref_root will be prependend to those URLs, value could be http://www.php.net or some other url more suitable for you. For example http://www.php.net/function.implode is a valid url.
Finally, there is docref_ext, which - if it exists - must start with a dot and this will be appended to the link. Useful if you need to add for example ".html" to the end of the links.
Good starting point in the documentation for all 3 is: http://www.php.net/manual/en/errorfunc.configuration.php#ini.html-errors
As for why - it makes it easier for beginner developers to figure out what any given error means.
My guess? So that the PHP developers can right-click and use "Copy Link" or the like to copy certain things out of errors rather than having to worry about highlighting the right text.