I started learning how to code in 2012 with HTML and CSS. Ever since the start of my coding journey, PHP has been one of the languages I’ve always ...
For further actions, you may consider blocking this person and/or reporting abuse
Learning PHP is a great choice, and I wouldn't be surprised if it's soon added to the list of technologies you love in your bio! For anyone interested, I would recommend PHP: The Right Way for solid advice on learning the language, as well as Laravel, a web application framework that makes coding with PHP a real pleasure. Best of luck with your exploration of PHP.
Laravel +1
Hey,
So I need to be the mean part here, I'm really sorry :/.
But there are a few "wrongs" in this article and I need to clarify
Syntax
While you CAN write
?>
at the end of your files, you really SHOULDN'T. In Javascript there are multiple competing syntax-standards (like the one from AirBNB or the "Standard" standard.), but PHP is more like Python: There are PSR-2 and PSR-12 which describe exactly how standard-compliant code should look like. No more fights over indentation and so on ;).php-fig.org/psr/psr-12/
Rules 2.2.:
Emphasis on the "only".
Standards
Btw the next thing missing (maybe you didn't stumble upon it yet) are other references to the PSR. To step up your game, you really should try to understand all of them. But PLEASE refer from PSR-8, as it's the wrong time for now.
Declaring Variables
define
doesn't really declare Variables, but compile time constants. They really can't be changed by any means and are like a little chipmunk replacing all the occurences with it's true value. This is the reason why you can't write sth. like:What you CAN do is simple math:
Declaring Arrays
Not really about declaring arrays, but you say, that an Array is the only way to create a collection of key/value pairs without importing.
But you really can (and should) use data classes which hold your data and data collection. Like in javascript you can use them in parameters without their content to be copied by whole, but as a reference!
Functions
Nothing wrong here, but keep in mind, that all Objects are implicitly called by reference, while all scalars (int, string, arrays) are copied by value!
And while we're here: Since the 7.x Versions PHP supports types!
You really should use them!
Classes
Not much here, but it's important to know, that you use
::
in static context, while->
in private. Additionally there's a difference between$this::$varname
andself::$varname
.She said and I quote:
So shes even more dependent on not learning sth. wrong.
How is someone supposed to learn and get better if everyone just sugar-coats you?
You might have missed the following comments and responses.
This comment:
Friendly reminder for a syntax shockingly difference between PHP and any other language. The dot ( . ) is the concatenation operator!
$hello = "hello";
$hello .= " world!";
echo $hello; // out: hello world!
For more info, check this out: positronx.io/php-concatenate-strin...
Her response:
I knew I was forgetting something, thank you!
Also this comment:
Setters are unnecessary in PHP. Use immutable private attributes and be happy.
Her response:
Thank you for the clarification!
And this:
Nice work Megan, just one thing: The spread operator is only available in PHP 7.4 everything else is awesome
And her response:
Thank you for the clarification! I'll add that in ASAP! 😀
I really appreciate this comment. Thank you so much! I'm still learning, so this is really helpful. 😊
I really didn't want to be mean. I'm just the direct kind of guy. Another very helpful resource:
phptherightway.com/
This is a lot. Really. One chapter a week should be good enough to get you in the top 10% :).
Another tip: try to use tools like phpstan (or psalm) and php mess detector as early and strict as possible. They really force you to write better :)
This brings back lots of memory from when I first learned PHP. Thank you.
When I find anyone who wants to know the similarities between JavaScript and PHP, I'll gladly point them to this post.
I'll bookmark it after hitting the submit button for this comment.
Awesome article! I started learning PHP awhile back and I always thought it has some similar style to JS. With you article, it confirmed my suspicion and learning about how classes work in PHP is so cool. Thank you for this :)
I'm so glad you enjoyed it!
PHP is awesome. Despite the rumours that it'll die soon.
Very nice article! You encouraged me to learn PHP.
Can I make recommendations on resources to get you started?
Of course! Go ahead.
Books
Website
Tools
Videos
*Security is important in Web application development and you should never consider it as an afterthought which is the main reason I included these resources.
I'm glad!
Friendly reminder for a syntax shockingly difference between PHP and any other language. The dot ( . ) is the concatenation operator!
$hello = "hello";
$hello .= " world!";
echo $hello; // out: hello world!
For more info, check this out: positronx.io/php-concatenate-strin...
I knew I was forgetting something, thank you!
It's really cool seeing things laid out like this where I can compare them to JavaScript! Branching out into a new language always feels a little intimidating to me but seeing the JS and PHP side by side makes it a little less intimidating.
I'm glad you enjoyed it, that makes me so happy!
Setters are unnecessary in PHP. Use immutable private attributes and be happy.
Thank you for the clarification!
Nice work Megan, just one thing: The spread operator is only available in PHP 7.4 everything else is awesome
Thank you for the clarification! I'll add that in ASAP! 😀
Forget php and start with java, i do both and java is the better one 😊
I think most people would be inclined to agree, but there are times where you need to maintain legacy systems written in PHP and it doesn't make sense to spend time and resources migrating it to a different technology stack, so knowing PHP still comes in handy!
This article is amazing. Nice and sweet, with code examples and explanations of what's going on. Anytime I hop to PHP I'll be looking at this article to brush up my skills.
I'm so glad you liked it!
Im talking about jdk and not js 😊
And it's still wrong. There are business cases for java and others for PHP. Both are valid languages, but none is superior to the other.
Btw: Would you show me your goto java solution which doesn't need dependencies, takes an json-url, gets the content and pretty prints its content in a file?
15s - I really want to see doing that in Java :D.
This is absolutely brilliant and exactly what I needed for my upcoming job interview.