Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Jaytee's avatar
Level 39

Riddle me this (PHP Error: No property on object)

Long time no speak to some of you. Okay, so we use LDAP for authentication at work on our internal server (intranet). I've come across an issue on a new application for one certain user. It's mind boggling shit.

// Active Directory. Does a search for the user's usercode. Gets this from $_SERVER['REMOTE_USER'];

e.g: REMOTE_USER = 'CORP\jth181';

// We do an explode on the remote user, get the usercode (the bit after CORP\); This all works fine

// This also works fine. Returns a user object
$adUser = $ad->getMyDetails();

Above is a basic rundown on how we get a user's credentials etc.

Now, if i run dd() on the $adUser, it's fine, we have a property called usercode. Typical stuff, we use it all the time by passing it through to User::firstOrNew(['usercode' => $adUser->usercode])

Here's where things get fucked up. There is one user who has a completely different structure to her usercode. Usually it's a alpha numeric string, but her's is firstname.lastname

When we do $adUser->usercode on this particular user, PHP throws an error saying the usercode property doesn't exist on the object. Try cast it to an array, and it complains about the index. Weird as fuck.

But yet, we can actually dd() on the object and dd() on $adUser->usercode, but the second we try call it, nope, doesn't work. Yep it's public etc.

I should explain, hers is the only usercode that is different. We have 50,000 employees in the company, with about 2-3000 of those that use this authentication method. I can also set a new property on the object and pass it the usercode (e.g: we manipulated it, by removing the dot out of the usercode), but the second we call that property, it complains too.

Any ideas?

0 likes
6 replies
jlrdw's avatar

What is firstname and lastname? I had a problem a while back where in my query I was using a mysql reserved word, and had to tick the field names. Have you tried wrapping it in {}. Or escaping.

Snapey's avatar

clearly the dot is being misinterpretted by eloquent

Any chance of switching this out once recieved from the api?

jlrdw's avatar

I normally don't have periods, but was curious. In my custom framework, pure PDO with bindings I entered a new name:

Mr.Big   // no space

It added, I was able to display, and edit, never no problem. So just thinking there may be an eloquent issue.

If PDO handles a period, and Mysql is handling it, then eloquent should as well.

Custom framework inserts via:

    public function insert($table, $data)
    {
        $newdata = array_keys($data);
        $stack = array();
        for ($i = 0; $i < count($newdata); $i++) {
            array_push($stack, '`' . $newdata[$i] . '`');
        }
        $fieldNames = implode(',', array_values($stack));
        $fieldValues = ':' . implode(', :', array_keys($data));
        $stmt = $this->prepare("INSERT INTO $table ($fieldNames) VALUES ($fieldValues)");

        foreach ($data as $key => $value) {
            $stmt->bindValue(":$key", $value);
        }
        $stmt->execute();
        return;
    }
Jaytee's avatar
Level 39

@jlrdw @snapey Well here's the other fucked up thing.

The name is Rosie.Hewett so definitely not a reserved issue. But, she can log in to other apps fine. Just not this one. However, she's had issues in the past with logging in to the other apps, but for some reason, it lets her in. Whats more is, Her account actually gets created in the database, but the exception is still thrown saying we couldn't find her.

We essentially say if there is no AD User then throw an exception, otherwise create the user. But what happens is, the user gets created from the AD Object, but then that exception is still thrown.

It's almost like its creating first, throwing the exception second, when it should be throwing the exception first and not continuing with creating. Now that's all fine, but if we remove that exception then we don't have anything in place for other users who may not actually exist. And once again, attempting to check the usercode fails so it's not like we can put a check in place. We can literally only dd on it. Fucking weird.

Jaytee's avatar
Level 39

@jlrdw @snapey

I don't like bumping old threads, but I thought i'd update you on what happened with this.

I no longer work for that company, so can't remember what the solution was as don't have access to the code. However, I remember it being something to do with how we were fetching the results from Active Directory. The model was being created correctly, but the wrong AD method was being called to check or something like that.

This wasn't an issue with eloquent misinterpreting the dot notation. It was purely my fault, but it was one of those silent errors where everything looks correct, and dd() returns the correct results. It was something extremely small, and not noticeable without a lot of testing. It took about 2 business days to find the issue.

Please or to participate in this conversation.