Undefined or defined index ? Decide - php

I have strange problem.
Line 61: $this->_currentRoute = Default_Model_Routes::getInstance()->getCurrentRoute();
.......... other code ..........
Line 86: var_dump(isset($this->_currentRoute['url']));
Line 87: var_dump($this->_currentRoute['url']);
Line 88: if ($this->_currentRoute['url'] == $currentUrl)
Line 89: $navigation[$key]['active'] = true;
Line 90: var_dump($this->_currentRoute);
This is result:
bool(true)
string(62) "cs/Polozka-menu-1/Polozka-menu-1-1/Polozka-menu-1-1-1/Clanek-1"
array(17) {
["url"]=>
string(62) "cs/Polozka-menu-1/Polozka-menu-1-1/Polozka-menu-1-1-1/Clanek-1"
["type"]=>
string(7) "article"
............
}
And in the error log:
[09-Mar-2011 19:49:32] PHP Notice: Undefined index: url in ...file... on line 87
[09-Mar-2011 19:49:32] PHP Notice: Undefined index: url in ...file... on line 88
Please, if you have any ideas where could be problem or how to fix, tell me.
Thank you :)
I have tried another test:
$test = array();
echo $test['lol'];
With this result:
Notice: Undefined index: lol in ...file... on line 92
Somethink really interesting: THIS 'lol' error is displayed in output, BUT the 'url' error IS NOT ! It is only in the log ... why ????? It's same file, line under the 'url' var_dump() ... crazy

What happens if you assign $this->_currentRoute to a variable first?
$route = $this->_currentRoute;
var_dump(array_key_exists('url', $route));
var_dump(isset($route['url']));
print "PRINTING: ".$route['url'];
die("ENDING ON LINE [".__LINE__."] !!!");
Solved (see comments)
This was unfortunately an issue with Zend Server, or bleeding edge PHP 5.3.3.

Maybe this is not you errors?
Try to ini_set('display_errors', 1);
And also see method Default_Model_Routes::getInstance()->getCurrentRoute()::__get()
Read this

Related

Undefined index: REQUEST_URI and HTTP_HOST

How can I get rid of this errors.
Line 8 : define('CURRENT_PAGE', basename($_SERVER['REQUEST_URI']));
Line 15: define('READ_PATH', $_SERVER['HTTP_HOST'].'/read.php?id=');
errors:
Undefined index: REQUEST_URI in ......... on line 8
Undefined index: HTTP_HOST in ....... on line 15
if you use CLI then u can check them for their existence but in the browser, HTTP_HOST will be available any time.
if (!empty($_SERVER['HTTP_HOST'])) {
define('CURRENT_PAGE', basename($_SERVER['HTTP_HOST']));
}
if (!empty($_SERVER['REQUEST_URI'])) {
define('CURRENT_PAGE', basename($_SERVER['REQUEST_URI']));
}

A PHP Error was encountered Severity: Notice Message: Undefined index: elements_id Filename: views/showdetail.php Line Number: 17

A PHP Error was encountered
Severity: Notice
Message: Undefined index: elements_id
Filename: views/showdetail.php
Line Number: 17
Help me please!
Error on server openshift but Run on localhost no error.
How to fix?
Do this with each variable
$elements_id=isset($row['elements_id'])?$row['elements_id']):'';
You are trying to use the vale of the index of the array without checking first if is set
<?php
print_r($dataelements);
foreach ($dataelements as $row) {
$elements_id =$row['elements_id'];
$elements_number = $row['elements_number'];
$elements_name = $row['elements_name'];
$elements_principle = $row['elements_principle'];
$elements_standard = $row['elements_standard'];
$elements_indicator = $row['elements_indicator'];
}
?>

Notice: Undefined variable: dbRead in C:\vhosts\phpcs5\lesson07\workfiles\scripts\user_registration.php on line 28

I'm getting this error and after checking for similar errors I verified the syntax is correct. The complete error is;
WRITE OK
READ OK
Notice: Undefined variable: dbRead in C:\vhosts\phpcs5\lesson07\workfiles\scripts\user_registration.php on line 28
Fatal error: Call to a member function quoteInto() on a non-object in C:\vhosts\phpcs5\lesson07\workfiles\scripts\user_registration.php on line 28
My connection is defined as:
$dbwrite = new Zend_Db_Adapter_Pdo_Mysql($write);
$dbread = new Zend_Db_Adapter_Pdo_Mysql($read);
I did a test first to make sure it can see the database which is what the Write OK and Read OK are as follows;
if ($dbwrite->getConnection()) {
echo 'WRITE OK<br/>';
}
if ($dbread->getConnection()) {
echo 'READ OK';
}
So I'm not sure why I'm getting this error.
dbRead is undefined. You've defined $dbread. Note the capitalization.
Look through your code base (particularly user_registration.php line 28) and switch all instances to one or the other.

twitteroauth : Notice: Undefined index: oauth_token in sometimes working sometimes not

so I tried using https://github.com/abraham/twitteroauth/blob/master/twitteroauth/twitteroauth.php
and sometimes I get :
Notice: Undefined index: oauth_token in /myweb/twitteroauth/twitteroauth.php on line 80
Notice: Undefined index: oauth_token_secret in /myweb/twitteroauth/twitteroauth.php on line 80
but sometimes it just run (confused ??)
the code in the twitteroauth.php line 80 :
function getRequestToken($oauth_callback) {
$parameters = array();
$parameters['oauth_callback'] = $oauth_callback;
$request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
//exit(print_r($request));
return $token;
}
so as u can see above I tried
exit(print_r($request));
the result was sometimes :
1
(error notice occurred)
and sometimes :
oauth_token=KzpRdIBm8inptvd3Xi254QUEsdf4f5eyO1XZyjW7xVU&oauth_token_secret=lmNl1rnBmR6palxHmufartersd0ivLabi5k&oauth_callback_confirmed=true1
(no error notice)
this is making me insane, can someone tell me what is the problem here ?
I tried looking at this thread : twitter oauth :geting undefined index: oauth_token_secret in
but doesn't help me :(
Thanks in advance !!
strange, it is working ok now, maybe it was my internet connection that have a problem =/

FACEBOOK API CALL - PHP SDK FATAL ERROR

trying to get every post and comment from a facebook page, I made this function that should go through the pagination:
$req = $facebook->api("/" . $pagename . "/?fields=posts.fields(message,link,created_time,shares,likes,comments)");
function parcours_arbre($ab)
{
GLOBAL $facebook;
GLOBAL $pagename;
$next = create_request($ab['posts']['paging']['next']);
$next_req = $facebook->api($pagename.$next);
$ab_next = $next_req['data'];
$prev = create_request($ab['posts']['paging']['previous']);
$prev_req = $facebook->api($prev);
$ab_prev = $prev_req['data'];
if (empty($ab)) {
display_results($ab['posts']['data']);
} else {
parcours_arbre($ab_next);
parcours_arbre($ab_prev);
}
}
I unfortunately get the following error:
Notice: Undefined index: posts in /form.php on line 36
Notice: Undefined offset: 3 in /utils.php on line 20
Notice: Undefined offset: 4 in /utils.php on line 20
Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /sdk/src/base_facebook.php on line 1271
Any idea how i could avoid it or what is going on? Would this go away if i use the "until" statement in my api request?
Thanks a lot,
To explain each error
the variable $ab which is an argument to the function, does not have a "posts" index. You should try to var_dump this variable so you can see what it actually looks like.
same as above
same as above
the api function takes 3. The path which should just be #pagename. The method ("GET" or "POST") most likely POST because GET is causing an error. The parameters, which should be array("fields" => "posts.fields(message,link,created_time,shares,likes,comments)")
I noticed that for next you have the code
$next_req = $facebook->api($pagename.$next);
but for previous you have
$prev_req = $facebook->api($prev);
Might want to look into this.

Categories