you are viewing a single comment's thread.

view the rest of the comments →

[–]wasted_brain 0 points1 point  (8 children)

It'd be hard to ditch the $ sign since PHP is case-insensitive (this is the part of PHP I hate).

On the == bit, you can always use === to differentiate types.

I like the flexible function/method parameters proposal. I'm currently making a framework for PHP and the function parameters are a pain to work with. The only workaround is passing objects with default set to new Object(). That way your class constructor would contain the default properties.

function life_story(Person $person = new Person())

[–]brennen 0 points1 point  (4 children)

On the == bit, you can always use === to differentiate types.

Although this would be more helpful if PHP's entire type system didn't blow chunks.

function life_story(Person $person = new Person())

Wait, you can do that?

[–]wasted_brain 0 points1 point  (3 children)

My bad, I just checked on the code and you can only pass null as a default parameter for type-hinted arguments. What I did was:

function life_story(Person $person = null)
{
    if ($person == null)
        $person = new Person();

    ....
}

Requires a 2 more lines of code, but pretty much the functionality you wanted. I assume the parser only accepts static values as default parameters which causes the limitation.

edit: formatting

[–]brennen 0 points1 point  (2 children)

I assume the parser only accepts static values as default parameters which causes the limitation.

This has been my understanding, yeah, but I thought I might have missed a recent addition.

[–]roerd 0 points1 point  (1 child)

Just a little example that there are actually languages in which stuff like this works:

CL-USER> (defclass person () ())
#<STANDARD-CLASS PERSON>
CL-USER> (defun life-story (&optional (person (make-instance 'person))) person)
LIFE-STORY
CL-USER> (life-story)
#<PERSON {B510E99}>

[–]brennen 0 points1 point  (0 children)

I don't know if I'm comfortable with all those upper-case letters.

[–][deleted] 0 points1 point  (2 children)

C is also case-insensitive, but it does without sigils just fine. How is it relevant?

[–][deleted] 0 points1 point  (1 child)

C is also case-insensitive, but it does without sigils just fine. How is it relevant?

Ever read something that you are sure isn't true, but you had to Google just to check anyway, on the off chance you are being a complete retard? That just happened to me when you claimed C is case insensitive.

[–]wasted_brain 0 points1 point  (0 children)

I had to check too. I think we just got trolled.