Home What am I doing wrong with my optional PHP arguments?
Reply: 0

What am I doing wrong with my optional PHP arguments?

user712
1#
user712 Published in May 20, 2018, 10:00 am

I have a the following class:

class MyClass {

    public function __construct($id = 0, $humanIdentifier = '') {
        $this->id = $id;
        $this->humanID = $humanIdentifier;
    }
}

So from my interpretation I should be able to pass either $id or $humanIdentifier to that constructor, neither or both if I wanted. However, when I call the code below I am finding that its the $id in the constructor args being set to hello world and not the $humanIdentifier, despite me specifying the $humanIdentifier when calling the constructor. Can anyone see where I am going wrong?

$o = new MyClass($humanIdentifier='hello world');
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310245 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO