php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38741 inconsistent feedback when accessing a null object
Submitted: 2006-09-07 12:06 UTC Modified: 2006-09-08 09:16 UTC
From: fh at ez dot no Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.6 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fh at ez dot no
New email:
PHP Version: OS:

 

 [2006-09-07 12:06 UTC] fh at ez dot no
Description:
------------
Accessing a null object will only result in a notice if 
you are accessing a property but a fatal error if you are 
trying to access a method. 

This is especially strange if the object you expected to 
access uses __get and so you actually expect your code to 
fail.

I think at the very least that the notice should be 
upgraded to a warning. An error is also in place since 
accessing a member variable of a null value is most 
probably a serious problem in your application.

Reproduce code:
---------------
<?php
$var = null;
echo $var->member; // notice
$var->member(); // fatal error
?>



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-08 09:16 UTC] tony2001@php.net
Undefined variables result in notices, as well as undefined attributes.
Undefined functions result in fatal errors, as well as undefined methods.
No bug here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 22:01:34 2025 UTC