Check 'present' methods in isset() implementation#25
Check 'present' methods in isset() implementation#25BenConstable wants to merge 3 commits intorobclancy:masterfrom
Conversation
|
Should just use Other than that this is a good PR. It needs to be on the develop branch though. |
|
Thanks very much for taking a look at this. I understand that calling methods in If you really don't want this behaviour however, then I don't think just using <?php
class MyPresenter extends \Robbo\Presenter\Presenter {
public function presentFullName()
{
if ($this->first_name && $this->last_name) {
return $this->first_name . ' ' . $this->last_name;
}
return null;
}
}
$p = new Presenter($object);
// This would be true, which would be confusing
if (isset($p->full_name)) {
echo $p->full_name;
} else {
echo $p->first_name;
}Sorry about the incorrect base branch - couldn't find any contribution notes so just went for |
|
I'm still not really seeing that use case as something you would do instead of just doing I just don't like the idea of executing a method just to see if it exists or returns null. Yeah contributing stuff should be written along with more details in the readme or even a proper set of documentation. You can just keep updating this PR and I will manually merge it into develop myself when it is ready. |
|
It was difficult to describe with a contrived example like the one I supplied, but you may be handing your view variables off to a third-party rendering library that uses What do you think would be a good alternative to making the method calls? As I said, I think using |
|
I'm going to get someone else's thoughts on this because I can't really decide. |
|
Ok, thanks. Will keep an eye on the thread! |
|
I'll put it in as is, but once I have time which might not be until the weekend. |
|
Great, thanks very much. If you do decide you want some changes just let me know. |
…esenter into develop closes #25
|
This is now merged with develop. |
I've updated the
isset()andoffsetExists()methods to check for the existence ofpresent{$VariableName}methods and their result, meaning that you can now do:This also works with arrays:
Hopefully this is something that you'll find useful. I've updated the unit tests to cover the changes.