Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Call to a member function count() on a non-object #171

Closed
lvandyk opened this issue Feb 24, 2014 · 9 comments
Closed

Call to a member function count() on a non-object #171

lvandyk opened this issue Feb 24, 2014 · 9 comments
Labels

Comments

@lvandyk
Copy link

lvandyk commented Feb 24, 2014

When validating I get the following error: Call to a member function count() on a non-object.

If I add this to the if statement on Ardent.php 526 it works: $this->validationErrors && ...

Is this a correct quick fix?

@igorsantos07
Copy link
Member

I couldn't find the line you're speaking, nor could understand your issue. Try to be more specific about what non-object variable were causing the error, or send directly a PR about the case. You can do everything through github itself, including editing the file :)

@Marwelln
Copy link

I got this problem too.

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

It's line 531 to 536 in Ardent\Ardent.php.

if ($success) {
    // if the model is valid, unset old errors
    if ($this->validationErrors->count() > 0) {
        $this->validationErrors = new MessageBag;
    }
}

You are trying to count() something that is null. A possible fix would be to check if it's false (or an object/array, don't really know how it works) before running count().

if (!$this->validationErrors || $this->validationErrors->count() > 0) {

@igorsantos07
Copy link
Member

Or we should make sure that validationErrors is always a valid object? What
makes more sense in the case?
On Mar 11, 2014 11:16 AM, "Martin Mårtensson" [email protected]
wrote:

I got this problem too.

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

It's line 531 to 536 in Ardent\Ardent.php.

if ($success) {
// if the model is valid, unset old errors
if ($this->validationErrors->count() > 0) {
$this->validationErrors = new MessageBag;
}
}

You are trying to count() something that is null. A possible fix would be
to check if it's false before running count().

if (!$this->validationErrors || $this->validationErrors->count() > 0) {

Reply to this email directly or view it on GitHubhttps://github.com//issues/171#issuecomment-37299827
.

@Marwelln
Copy link

I'll leave that up to you. I don't know how the code works, sorry.

@igorsantos07
Copy link
Member

Yeah, that was more like a reminder for when this issue is looked again (:
Sorry for not pointing that earlier.
On Mar 13, 2014 12:35 PM, "Martin Mårtensson" [email protected]
wrote:

I'll leave that up to you. I don't know how the code works, sorry.

Reply to this email directly or view it on GitHubhttps://github.com//issues/171#issuecomment-37547316
.

@calmdev
Copy link

calmdev commented Apr 29, 2014

Resolved in #201

@tomxc
Copy link

tomxc commented May 20, 2014

See here for solution without any changes to Ardent.php: #128 (comment)

@calmdev
Copy link

calmdev commented Jun 27, 2014

@tomxc your suggestion works just fine — thanks.

@igorsantos07
Copy link
Member

this is fixed by #225

@igorsantos07 igorsantos07 removed the RFC label May 10, 2015
igorsantos07 added a commit that referenced this issue May 10, 2015
igorsantos07 added a commit that referenced this issue May 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants