user-documentation icon indicating copy to clipboard operation
user-documentation copied to clipboard

Accessing a property on null currently emits a notice, not an error or exception

Open muglug opened this issue 3 years ago • 3 comments

Please complete the information below:

Where is the problem?

4064: Accessing members on a nullable object

Accessing a property or a method on null will throw an exception.

What is the problem?

Accessing a property on null currently emits a "Notice"


Please don't change anything below this point.


  • Build ID: HHVM=HHVM-4.164.0:HSL=v4.108.1:2022-09-19T20:50:52+0000:1fa47f258c6b68f8ec01899aa82fd6ffa0957109
  • Page requested: /hack/silencing-errors/error-codes
  • Page requested at: Tue, 20 Sep 2022 15:40:28 +0000
  • Controller: GuidePageController

muglug avatar Sep 20 '22 15:09 muglug

On my local environment:

> null->foo()
Hit a php exception : exception 'BadMethodCallException' with message 'Call to a member function foo() on a non-object (null)'

This probably depends on the HHVM settings if we aren't always throwing in this case.

Wilfred avatar Oct 01 '22 00:10 Wilfred

You're calling a method on null, not performing a property fetch on null.

muglug avatar Oct 07 '22 19:10 muglug

Huh, you're right.

> p null->foo

Notice: Cannot access property on non-object

Notice: Cannot access property on non-object
null

I should update the docs, although I'm surprised HHVM doesn't enforce this more strictly yet.

Wilfred avatar Nov 17 '22 19:11 Wilfred