There are various things missing or not working in your code example. It doesn’t change the meaning you’re trying to convey, of course, but it makes it look like you rushed and didn’t pay attention to details.
Parameter is string imageUrls (it’s missing the dollar sign) but you iterate over it so it should be an array, not a string.
thrownew\Exception('We could'ntfindimage');
Syntax error: either escape the apostrophe or surround the message with double quotes.
I know it’s not the scope of your post but you could have passed $imageNames as param to avoid referencing a variable outside of the function scope.
$imageName=$imageNames[$index];
Talking about too many variables you can just return a Boolean here:
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
There are various things missing or not working in your code example. It doesn’t change the meaning you’re trying to convey, of course, but it makes it look like you rushed and didn’t pay attention to details.
Parameter is
string imageUrls
(it’s missing the dollar sign) but you iterate over it so it should be an array, not a string.Syntax error: either escape the apostrophe or surround the message with double quotes.
I know it’s not the scope of your post but you could have passed
$imageNames
as param to avoid referencing a variable outside of the function scope.Talking about too many variables you can just return a Boolean here:
Something like:
I like the idea of showcasing code smells but it would look better with working code IMHO.
Hi
Thank you very much for taking the time to correct the code.
I've made several of your suggestions.
I treat code as pseudocode and not real one
More on this here
I Wrote More than 90 Articles on 2021: Here is What I Learned
Maxi Contieri ・ Dec 31 '21 ・ 4 min read
I've also decided not to use 'php list()' returning more than one argument because it is not common on other languages