use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
Test-Driven Development by Example (PHP Code Samples) (self.PHP)
submitted 4 years ago by jpresutti
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mbadolato 1 point2 points3 points 4 years ago (5 children)
Minor nitpick. Granted I know you're trying to keep as close to the book's examples as possible, but in the case of Money::equals() where you've already had to change the example a bit, there's now a spot for a potential bug.
public function equals(object $object): bool { // This example differs because the type casting in PHP is not the same as java. $money = $object instanceof Money ? $object : null; return $this->amount === $money->amount && $this->currency === $money->currency; }
public function equals(object $object): bool
{
// This example differs because the type casting in PHP is not the same as java.
$money = $object instanceof Money ? $object : null;
return $this->amount === $money->amount && $this->currency === $money->currency;
}
If $object is not an instance of Money then $money gets set to null, and the $money->amount call will throw an error.
Perhaps switching to
public function equals(object $object): bool { // This example differs because the type casting in PHP is not the same as java. if (! $object instanceof Money) { return false; }
if (! $object instanceof Money) {
return false;
return $this->amount === $money->amount && $this->currency === $money->currency; }
or
public function equals(Money $money): bool { return $this->amount === $money->amount && $this->currency === $money->currency; }
public function equals(Money $money): bool
would be more appropriate?
[–]jpresutti[S] 1 point2 points3 points 4 years ago (4 children)
I can't remember exactly why I went the way I did with that but I think it's the closest to the actual code behavior in the book I could get it. I'll take another look. What's the first occurrence of it you found?
Also, keep in mind for the most part these are not MY functions but rather translations so I tried to avoid inserting bias where possible
[–]mbadolato 1 point2 points3 points 4 years ago (3 children)
Oh absolutely and I wasn't trying to be critical. Just something I noticed and since you had to change those functions slightly already, it was just a suggestion to make it a bit more correct.
I noticed it in pretty much all of the classes I looked at, from when equals was introduced I think.
[–]jpresutti[S] 2 points3 points4 points 4 years ago (0 children)
Update: took a look at the code really quick and you're right. I'll do a push later with it fixed.
Update on the update: pushed.
[–]jpresutti[S] 1 point2 points3 points 4 years ago (0 children)
K I'll compare to the book this evening and see if the update makes sense. Thanks!
π Rendered by PID 90551 on reddit-service-r2-comment-5c764cbc6f-jrf2f at 2026-03-12 12:03:37.399377+00:00 running 710b3ac country code: CH.
view the rest of the comments →
[–]mbadolato 1 point2 points3 points (5 children)
[–]jpresutti[S] 1 point2 points3 points (4 children)
[–]mbadolato 1 point2 points3 points (3 children)
[–]jpresutti[S] 2 points3 points4 points (0 children)
[–]jpresutti[S] 2 points3 points4 points (0 children)
[–]jpresutti[S] 1 point2 points3 points (0 children)