Skip to content
This repository

better error returned if checked is_object #1817

Closed
wants to merge 1 commit into from

1 participant

gxela
gxela
gxela commented March 25, 2013

I don't have 'address' field in mysql table and created get_address()...

before:

Unhandled Exception


Message:


Call to a member function results() on a non-object

Location:


/var/www/app/laravel/database/eloquent/model.php on line 680

after:

Unhandled Exception


Message:


Undefined property: CustomerAddress::$address

Location:


/var/www/app/laravel/database/eloquent/model.php on line 678

Stack Trace:


#0 /var/www/app/laravel/laravel.php(42): Laravel\Error::native(8, 'Undefined prope...', '/var/www/app...', 678)
#1 /var/www/app/laravel/database/eloquent/model.php(678): Laravel{closure}(8, 'Undefined prope...', '/var/www/app...', 678, Array)
#2 /var/www/app/laravel/view.php(386) : eval()'d code(61): Laravel\Database\Eloquent\Model->__get('address')
#3 /var/www/app/laravel/view.php(386): eval()
#4 /var/www/app/laravel/view.php(353): Laravel\View->get()
#5 /var/www/app/laravel/view.php(590): Laravel\View->render()
gxela fixed case where result() is called on non object; the error is not v…
…erbose so adding this check makes it a little more verbose
6765ce7
gxela gxela closed this March 25, 2013
gxela
gxela commented March 25, 2013

bad idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 25, 2013
gxela fixed case where result() is called on non object; the error is not v…
…erbose so adding this check makes it a little more verbose
6765ce7
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  laravel/database/eloquent/model.php
2  laravel/database/eloquent/model.php
@@ -675,7 +675,7 @@ public function __get($key)
675 675
 		// If the item is not a loaded relationship, it may be a relationship
676 676
 		// that hasn't been loaded yet. If it is, we will lazy load it and
677 677
 		// set the value of the relationship in the relationship array.
678  
-		elseif (method_exists($this, $key))
  678
+		elseif (method_exists($this, $key) && is_object($this->$key))
679 679
 		{
680 680
 			return $this->relationships[$key] = $this->$key()->results();
681 681
 		}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.