Skip to content

Implement boolval() - #60

Closed
Jille wants to merge 3 commits into
php:masterfrom
Jille:master
Closed

Jille wants to merge 3 commits into
php:masterfrom
Jille:master

Conversation

@Jille

@Jille Jille commented Apr 18, 2012

Copy link
Copy Markdown
Contributor

Implementation based on strval()

@nikic

nikic commented Apr 18, 2012

Copy link
Copy Markdown
Member

How is this different from (bool) $var?

@Jille

Jille commented Apr 18, 2012

Copy link
Copy Markdown
Contributor Author

It isn't, but this is usable as callback.

@cataphract

Copy link
Copy Markdown
Contributor

@laruence That's not the same thing. For instance, it will fail if you pass an array, while convert_to_boolean works with any variable. @Jille 's implementation seems correct to me, though he could use convert_to_boolean_ex to avoid a separation if it's not necessary.

@Jille

Jille commented Apr 19, 2012

Copy link
Copy Markdown
Contributor Author

I accidentally also committed the convert_to_boolean -> convert_to_boolean_ex in the previous commit. I'm not sure whether that is the only change required.

@cataphract

Copy link
Copy Markdown
Contributor

@Jille Sorry, disregard that last part of my comment. convert_to_boolean_ex is not a good idea here (more cycles, though it would still work), because it precedes a copy anyway. Since return_value is only a zval * and not zval **, that copy is necessary.

@smalyshev

Copy link
Copy Markdown
Contributor

With anon functions, I'm not sure why function($x) { return (bool)$x;} doesn't really solve this use case.

@Jille

Jille commented Apr 19, 2012

Copy link
Copy Markdown
Contributor Author

Most of all it's a consistency improvement. We have strval, doubleval, floatval and intval so one would assume boolval also exists.

@Jille

Jille commented Apr 24, 2012

Copy link
Copy Markdown
Contributor Author

Should this be discussed on the internals list? Should I open a bug and hope someone will merge it? Should I just wait till someone hits the "Merge" button?

@nikic

nikic commented Apr 24, 2012

Copy link
Copy Markdown
Member

@Jille You should bring this up on internals. It adds a new function, so it can't be simply merged. Also it's debatable whether we really need it, so... writing a mail to internals should be the right thing to do :)

@dsp

dsp commented May 2, 2012

Copy link
Copy Markdown
Member

It makes sense to add it to 5.5

@dsp

dsp commented Jun 6, 2012

Copy link
Copy Markdown
Member

Add a test please and I will pull it. Also squash 90a3d47 and a5d113e together (if not I can do that myself)

@Jille

Jille commented Jun 6, 2012

Copy link
Copy Markdown
Contributor Author

74b4ef5 (in my boolval-branch) contains the function and a test. Thanks!

@dsp dsp closed this Jun 7, 2012
@dsp

dsp commented Jun 7, 2012

Copy link
Copy Markdown
Member

Merged as 753c336. Thank you for your contribution.

@dsp

dsp commented Jun 7, 2012

Copy link
Copy Markdown
Member

Would be great if you can also help the docteam adding that function to phpdoc :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants