Home  >  Article  >  Backend Development  >  Notice: Trying to get property of non-object problem(PHP) solution_PHP tutorial

Notice: Trying to get property of non-object problem(PHP) solution_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:19:50825browse

I actually called a zend database access method here, using the fetchAll method, but since there is no such record in the database, the returned object is null, so I judge whether the object is null:

Copy code The code is as follows:

if($obj==null){
...
}

The result of writing like this is to generate the above notice, which is really strange. The object is null and cannot be accessed?

After checking the information, I found that to determine whether it is null, you need to judge like this:

Copy the code The code is as follows:

if (isset($obj)) {
echo "This var is set set so I will print.";
}

This isset is done What?

isset function is to detect whether the variable is set.

Format: bool isset ( mixed var [, mixed var [, ...]] )

Return value:

If the variable does not exist, return FALSE
If the variable exists and its value is NULL, it also returns FALSE
If the variable exists and its value is not NULL, it returns TRUE
When checking multiple variables at the same time, TRUE is returned only when each single item meets the previous requirement. Otherwise the result is FALSE
If a variable has been released using unset(), it will no longer be isset(). If you use isset() to test a variable that is set to NULL, it will return FALSE. Also note that a NULL byte ("



http://www.bkjia.com/PHPjc/325251.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/325251.htmlTechArticleI actually called a zend database access method, using the fetchAll method, but since there is no This record, so the returned object is null, so I judge it...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn