Better PHP Notices - php

Is there a way to make php notices more informative? For example, I'm getting notices such as
Notice: Undefined offset: 1 in /home/anon/public_html/MotE/lib/Bullet.php on line 18
while running file() to store each line in an array and then exploding each line in the array by \t. Is there a way to have the notice show me which line in the file I'm reading from is causing the issue?
I would like to know if there is a way to make php notices more informative?
Perhaps something like
Notice: Undefined offset: 1 in /home/anon/public_html/MotE/lib/Bullet.php on line 18 [File: /feed.csv]
If I do something like
echo 'line: ' . $arrKey . '<br />';
the notices all disappear but echoing that much information is undesirable and provides no useful information since the notices disappear.

You can look at Xdebug - it will print backtrace for you.
More info here: How can I get PHP to produce a backtrace upon errors?

Related

PHP disable error from specific file?

I am getting hundreds of from ANSI.php. Here is an example:
/usr/share/pear/File/ANSI.php on line 553 Notice: Undefined offset: 75 in
/usr/share/pear/File/ANSI.php on line 555 Notice: Undefined offset: 76 in
/usr/share/pear/File/ANSI.php on line 553 Notice: Undefined offset: 76 in
/usr/share/pear/File/ANSI.php on line 555 Notice: Undefined offset: 77 in
/usr/share/pear/File/ANSI.php on line 555 Notice: Trying to get property of non-object in
/usr/share/pear/File/ANSI.php on line 496 Notice: Trying to get property of non-object in
This is generating from:
$ansi->appendString($ssh->read());
Everything is working. I suspect the old machines I am working with are giving ANSI.php a hard time.
Is there a way i can disable just the error messages from ANSI.PHP and keep the others? Unless someone has a way of fixing the error.
Simplest Solution (Sub-Optimal)
I guess the simplest way to suppress the errors would be to use the error suppression operator #. eg.
#$ansi->appendString($str);
Optimal Solution (Possibly)
There have been two commits to phpseclib since the latest release (1.0.7 and 2.0.6, as of this post) that fixed issues with File/ANSI.php:
https://github.com/phpseclib/phpseclib/commit/5c792f6bc1fa8a5d26b43fb8200191c073637e15
https://github.com/phpseclib/phpseclib/commit/84d1628cb7734134b1ba80545b38985025942b79
More info:
https://github.com/phpseclib/phpseclib/issues/1161
https://github.com/phpseclib/phpseclib/issues/1150
Kinda makes me wonder if one of those might fix the issue for you.
Fallback to Optimal Solution
If the previously mentioned "optimal solution" doesn't fix the issue for you then it would be nice to fix the problem at the source. What'd help me do that would be a copy of the data you got before you passed it to $ansi->appendString(). To make it so the characters don't get garbled because they're extended ASCII maybe hex encode it. eg. echo bin2hex($ssh->read()); or something.

PHP Errors Cond and 1 more

currently Developing a website for my local isp, anyway they want a speed test, soo oolka net gauge is out of the question so i chose http://www.v-speed.eu I quite like their UI but anyway i get these errors on the main page
Notice: Undefined index: link in C:\xampp\htdocs\speed\index.php on
line 48
Notice: Undefined variable: cond in
C:\xampp\htdocs\speed_class\class.core.php on line 961
Notice: Undefined variable: cond in
C:\xampp\htdocs\speed_class\class.core.php on line 990
Notice: Undefined offset: 5 in
C:\xampp\htdocs\speed_class\class.core.php on line 1022
Couldn't figure it out
http://pastebin.com/s1tMEMaf
Just want to fix this
$sql = "
SELECT
COUNT(id) AS count
FROM
boxes
WHERE
1 ".$cond."
ORDER BY
order ASC
";
well You are using a variable ($cond) in a method where it is not defined yet.
How are you suppose to append something to something that is not there. (starting on line 948 )
You might want to start with $cond = "";
or
if($text) $cond = " AND (`name` LIKE :text)";
Your undefined offset on 1022 means that your probably get NULL on a key that you are trying to get that does not exist.
As Rahul stated, you should read the error messages properly. The errors you mention tell a lot already and should give enough information for you to debug it.

xampp Notice: Undefined offset

Can anyone help me with this error? When running the site on my host i get no errors but when i run it with xampp on my pc i get this
Notice: Undefined offset: 1 in C:\xampp1\htdocs\ctcoun1kk\countrycheck.php on line 273
Notice: Undefined offset: 2 in C:\xampp1\htdocs\ctcoun1kk\countrycheck.php on line 273
Notice: Undefined offset: 3 in C:\xampp1\htdocs\ctcoun1kk\countrycheck.php on line 273
Line 273 is this one->
$decip = ($numbers[0]*16777216)+($numbers[1]*65536)+($numbers[2]*256)+($numbers[3]);
function x_dot2dec($dotip) {
$numbers = preg_split( "/./", $dotip);
$decip = ($numbers[0]*16777216)+($numbers[1]*65536)+($numbers[2]*256)+($numbers[3]);
return array ($decip, $numbers[0]);
}
Thank you for any help :)
It means that $numbers variable is not set properly. Before 273 line put:
var_dump($numbers);
and check if indexes 0,1,2 and 3 are set
Those are just notices. The script should work fine if you ignore thos. Set error reporting level using error_reporting (http://www.php.net/manual/en/function.error-reporting.php) and those will go away. This is set on your other server- that's why you don't see these "errors".
error_reporting(0); //disable all errors and notices

Undefined index: name in Dataset.php after upgrade to php 5.3

PHP Notice: Undefined index: parentid in /home/public_html/data/Dataset.php on line 319
PHP Notice: Undefined index: destinations in /home/public_html/data/Dataset.php on line 330
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice: Undefined index: name in /home/public_html/data/Dataset.php on line 220
PHP Notice: Undefined index: fieldhelp in /home/public_html/data/Dataset.php on line 236
My script refuses to work after upgrading to php 5.3 from 5.2. I am seeing many PHP Notice in the log.
at line 319: if( $this->aFields["parentid"] ) {
at line 340: if( $curField["radiogroup"] ) {
I suspect the problem is in another file which contains many such lines
if( isset( $this->request_vars[$name]["id"] ) ) {
how do i fix this? if it's that easy by judging from above.
It's not an error. It says that there's no element with index "radiogroup" etc. in array $curField.
You have to check if is it present first using isset, for example:
if(isset($curField['radiogroup']) and $curField['radiogroup']) {
Undefined index means that you try to access a key of an associative array that doesn't exist. This should be present in your old configuration but due to the error reporting level it never came up.
You should alter your code in order to first test if the variable is set and then use it.
For example:
Change occurrences of the form:
if( $this->aFields["parentid"] ) {
...
}
to
if( isset($this->aFields["parentid"]) ) {
...
}
From the PHP documentation (error_reporting):
<?php
// Turn off all error reporting
error_reporting(0);
?>
Other interesting options for that function:
<?php
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
Hard to tell from the code, but I presume the error reporting level has changed, making it now display notices. However, if its possible a variable may not exist, you should use something like:
if( isset($this->aFields["parentid"]) ) {
In your case you could use empty, as that would check its both set and has a value and its not equal to 0/false (same as original line)
if( ! empty($this->aFields["parentid"]) ) {

Notice: Undefined offset: 1 in /somepath/index.php on line 14

I got a problem, I get an error with this code:
$totalpages = substr($totalpages[1],0,1);
The weird thing is, the code works?
This is the error i get:
Notice: Undefined offset: 1 /some/spath.php on line XX</code>
if (isset($totalpages[1]))
$totalpages = substr($totalpages[1],0,1);
BTW, you're getting a notice - not an error. That's the reason why your code still works.
u should check is_array($totalpages) ...
or ini_set('error_reporting', E_ALL & ~E_NOTICE);
more details on error reporting
before you set totalpages to whatever value you set it to, set it as a array $totalpages=array(); OR suppress the warning $totalpages = substr(#$totalpages[1],0,1);

Categories