Undefined property:View::$title in <b>C:\.....\components\.....\views\...\tmpl\default.php - php

I am seeing an undefined property warning PHP notice on my registration form in Joomla 2.5 , wondering whats causing this issue. Its happening on the lines which try to echo with $this
<?php if($this->title == 'Me'){echo "selected=\"selected\"";}?>>Me</option>
Update: $this in this case is referring to the correct class. Its the $title thats the issue which is prompting the undefined property issue. Whats the remedy to use variables in a php file which have not been defined yet?
Thanks.

As the message indicated that it is an undefined variable, after running xdebug I noticed that it was not being set and that was the issue. Thus checking if the variable is set and only then using the variable would help.

Related

PHP Undefined offset: 0 with isset

I am trying to understand if it's correct for PHP to throw an undefined offset error when using isset() function.
The data comes from an eloquent collection.
$interest->vehicles
The problem happens when the collection is empty.
Below code tested on 3 different setups (Mac+Mamp PRO, Windows+Xampp, Mac+Mamp), throws an undefined offset in first two setups but not in mine which is the third one (Mac+Mamp)
All tested scenarios are done with PHP 7 and display errors On.
isset($interest->vehicles[0]['make'])
I understand why the error may be happening to the other setups as the offset i try to isset doesn't exist, but the thing i don't understand is why i don't see the error on my setup when using isset.
I also tried to reinstall Mamp on my maching, upgraded to Sierra OS, restarted my laptop, changed php.ini settings to always display all errors .
ErrorException in Collection.php line 1043:
Undefined offset: 0 (View: /Users/efood-leo/Sites/cardealer/resources/views/panel/interest/form.blade.php) (View: /Users/efood-leo/Sites/cardealer/resources/views/panel/interest/form.blade.php)
This is the error i am talking about, and happens only if i try to retrieve
$interest->vehicles[0]['make']
When the vehicles[0] does not exist.
if i do :
isset($interest->vehicles[0]['make'])
Then there is no error in my setup, and 2 other devs report the error still happens with isset.
Try this code.
Isset() function is returning true somehow so without isset it works
$interest = (object)['vehicles' => []];
echo $interest->vehicles[0]['make'];
Read more on isset():
http://php.net/manual/en/function.isset.php

Smarty internal error

Looking through the server PHP error log has revealed that a certain type of PHP Notices comes up as the most frequent, and it has to do with Smarty. I've found a question which seems to describe the same error, but there is actually no answer.
The notice is the following (there are different variables stated as undefined):
PHP Notice: Undefined variable: is_admin in /usr/share/php/Smarty/sysplugins/smarty_internal_data.php on line 291
I wonder how I can possibly debug this one since no data (like template name) is provided.
Below I'm gonna give you some idea of the code (which you can read in full detail here since it's all open-source).
So there is one global smarty object which is created in a file called header.php, and further in the same file some global smarty variables are set, including the one from the notice above:
//init Smarty
require_once('Smarty.class.php');
$smarty = new Smarty();
...
$smarty->assign('is_admin', is_admin() ? 1 : 0);
This header.php is then included in every file that needs to show some HTML by calling $smarty->display(...). So I presume that in any file where the $smarty object is present this object has a variable called is_admin. However, it doesn't seem to be the case.
Additionally, "normal" Smarty warnings about unset variables look differently:
PHP Notice: Undefined index: sent_id in /var/www/smarty_dir/templates_c/a5aab2c66c44442365a39981ba9be18e0a1f11ad.file.history.tpl.cache.php on line 123
Any ideas?
Upd.
I've read some logs and I see that such warnings seemingly arise when a user enters a page and gets 302 HTTP status. This may be due to the following code (which is placed after smarty constructor call but before the variables are assigned:
//cookie check
if (!is_logged() && isset($_COOKIE['auth'])) {
if ($user_id = check_auth_cookie()) {
if (user_login('', '', $user_id, $_COOKIE['auth'])) {
header("Location:".$_SERVER['REQUEST_URI']);
return;
}
}
}
So I guess I should move $smarty initialisation after this block and it is likely to help. Still I'm curious about how it relates to the issue.
I think I got it. The issue is really in the piece of code including
header("Location:".$_SERVER['REQUEST_URI']);
return;
My error is that return does not act like exit in this case, because when you call return from a file which is required or incuded into another one, you just return the control to that another file. I wasn't aware of this feature.
'is_admin', is_admin() you are trying to assign the function is_admin() as a variable {$is_admin} to the Smarty template, which according to me, is impossible.
Assign the return result to a variable i.e.:
$var = is_admin();
$smarty->assign('is_admin', $var);

php undefined variable session_register issue

There was a php project which was already in live server. Now my work is to change some style issues. So for that I just downloaded all the files from the server along with the database. After that I made all the necessary setup on my localhost(LAMP). Now when I browse the page I got some error like
Notice: Undefined variable: _session_register in path to the folder/file session.php on line 8
Now on line 8 I can see this code
$_session_register["esb2b_username"];
$_session_register["esb2b_userid"];
$_session_register["esb2b_memtype"];
$_session_register["esb2b_adv_id"];
$_session_register["esb2b_adv_email"];
$_session_register["lang"];
After searching over google I came to know that session_register in php is deprecated. So what will be the best solution to solve this issue in a fine way? Any help and suggestions will be appreciable. Thanks
There's a function called session_register that is deprecated, but what you have in the question is a variable. You are getting this notice because you are using array-access on it and it is undefined. This works, but it is better practice to define it as an empty array first.
$_session_register this is wrong use $_SESSION
session_register is a function which is deprecated. (Way which you written now is also wrong)
$_session_register["esb2b_username"]; change it to $_SESSION["esb2b_username"] = "";

PHP Call to undefined function

I am trying to call a function from another function. I get an error:
Fatal error: Call to undefined function getInitialInformation()
in controller.php on line 24
controller.php file:
require_once("model/model.php");
function intake() {
$info = getInitialInformation($id); //line 24
}
model/model.php
function getInitialInformation($id) {
return $GLOBALS['em']->find('InitialInformation', $id);
}
Things already tried:
Verified that the require_once works, and the file exists in the specified location.
Verified that the function exists in the file.
I am not able to figure this out. Am I missing something here?
How to reproduce the error, and how to fix it:
Put this code in a file called p.php:
<?php
class yoyo{
function salt(){
}
function pepper(){
salt();
}
}
$y = new yoyo();
$y->pepper();
?>
Run it like this:
php p.php
We get error:
PHP Fatal error: Call to undefined function salt() in
/home/el/foo/p.php on line 6
Solution: use $this->salt(); instead of salt();
So do it like this instead:
<?php
class yoyo{
function salt(){
}
function pepper(){
$this->salt();
}
}
$y = new yoyo();
$y->pepper();
?>
If someone could post a link to why $this has to be used before PHP functions within classes, yeah, that would be great.
This was a developer mistake - a misplaced ending brace, which made the above function a nested function.
I see a lot of questions related to the undefined function error in SO. Let me note down this as an answer, in case someone else have the same issue with function scope.
Things I tried to troubleshoot first:
Searched for the php file with the function definition in it. Verified that the file exists.
Verified that the require (or include) statement for the above file exists in the page. Also, verified the absolute path in the require/include is correct.
Verified that the filename is spelled correctly in the require statement.
Echoed a word in the included file, to see if it has been properly included.
Defined a separate function at the end of file, and called it. It worked too.
It was difficult to trace the braces, since the functions were very long - problem with legacy systems. Further steps to troubleshoot were this:
I already defined a simple print function at the end of included file. I moved it to just above the "undefined function". That made it undefined too.
Identified this as some scope issue.
Used the Netbeans collapse (code fold) feature to check the function just above this one. So, the 1000 lines function above just collapsed along with this one, making this a nested function.
Once the problem identified, cut-pasted the function to the end of file, which solved the issue.
Many times the problem comes because php does not support short open tags in php.ini file, i.e:
<?
phpinfo();
?>
You must use:
<?php
phpinfo();
?>
Your function is probably in a different namespace than the one you're calling it from.
http://php.net/manual/en/language.namespaces.basics.php
I happened that problem on a virtual server, when everything worked correctly on other hosting.
After several modifications I realized that I include or require_one works on all calls except in a file.
The problem of this file was the code < ?php ? > At the beginning and end of the text.
It was a script that was only < ?, and in that version of apache that was running did not work
This is obviously not the case in this Q,
but since I got here following the same error message I though I would add what was wrong with my code and maybe it will help some one else:
I was porting code from JS to PHP and ended up having a class with some public method.
The code that was calling the class (being code that originated from JS) looked something like:
$myObject.method(...)
this is wrong because in PHP it should look like this:
$myObject->method(...)
and it also resulted with "PHP Call to undefined function".
change to use -> and the problem was solved.
Presently I am working on web services where my function is defined and it was throwing an error undefined function.I just added this in autoload.php in codeigniter
$autoload['helper'] = array('common','security','url');
common is the name of my controller.
Please check that you have <?PHP at the top of your code. If you forget it, this error will appear.

PHP Parts Property

I'm working on some code written by another developer and it is written in PHP. There is a line of code that is causing an error. I'm thinking that it is something you have to enable for PHP because it works just fine in another environment but doesn't work on the new environment and I haven't changed the code yet. The line is:
$structure->parts
$structure is a variable I've passed in but from a search online parts is a property. The error I'm getting says:
Undefined property: stdClass::$parts
Thanks for any help or ideas anyone might have.
Looks like parts doesn't exist there. Try running var_dump($structure) to get a better picture of what you're really dealing with.

Categories