PHP 5.4: disable warning “Creating default object from empty value”

前端 未结 4 1925
萌比男神i
萌比男神i 2020-12-10 05:16

I want to migrate code from PHP 5.2 to 5.4. This worked fine so far except that all the code I use makes extensive use of just using an object with a member without any init

4条回答
  •  再見小時候
    2020-12-10 05:56

    Technically you could do this by installing your own error handler for warnings. From inside the handler check the string error message; if it's the one you want to suppress then return true, otherwise return false to let the default error handler do its thing.

    However I would still recommend doing the right thing and manually fixing your code wherever this misuse does appear because, if nothing else, it gets you into the correct habit. Unless this is paid work (in which case there usually are concerns that override purity of implementation), consider this as a lesson and do the right thing.

提交回复
热议问题