如何学习php_如何学习PHP

如何学习php

This is the second piece of my series on how to start a Software Development career. I recommend giving that a quick read if you haven’t already.

这是我 如何开始软件开发事业 系列的第二篇文章 如果您还没有的话,建议您快速阅读一下。

Image for post
© Eddie Carrasco
©埃迪·卡拉斯科(Eddie Carrasco)

I’ve been writing PHP since 2011. Despite having years of experience under my belt, I still don’t feel like an expert. A big part of that is because the language continues evolving, so there’s always something new to learn. Even from my point of view, figuring out what’s new and how it could be applied practically can be a daunting task.

自2011年以来,我一直在编写PHP。尽管我有多年的工作经验,但我仍然不觉得自己是专家。 其中很大一部分是因为语言在不断发展,因此总会有一些新东西要学习。 即使从我的角度来看,弄清楚什么是新的以及如何在实践中应用它可能是一项艰巨的任务。

Suppose though if I were to bring my 2011 self to today, where I was just beginning my PHP journey. What advice would I give to that naïve, bright-eyed kid so that he could pick up the language in as short amount of time as possible?

假设如果我将2011年的自我带到今天,那正是我刚刚开始PHP旅程的地方。 我会给这个天真,聪明的孩子什么建议,以便他能在尽可能短的时间内掌握该语言?

I’d start of by telling him that what I can provide is a roadmap with the goal of becoming technically proficient in PHP, while attempting to help avoid some pitfalls and delays. What I can’t provide is a PHP manual. I’d only be highlighting essential points of interest that must be grasped to become a PHP developer. Anyone with this information should have a good enough understanding to know where and how to proceed next (don’t worry, I’ll give some suggestions for that as well).

首先,我要告诉他,我可以提供的路线图旨在在技术上精通PHP,同时尝试避免某些陷阱和延迟。 我无法提供的是PHP手册 。 我只是要强调成为PHP开发人员必须掌握的重要兴趣点。 掌握了这些信息的任何人都应该具有足够的了解,知道下一步该如何进行以及如何进行(不要担心,我也会为此提供一些建议)。

环境 (Environment)

Schools provide an environment for people to learn a subject matter, the same applies to PHP. Before we even begin writing our first lines of PHP code we need to make sure we’ve set up the proper environment first. Nowadays, a tool called Docker makes that super easy.

学校为人们提供了学习主题的环境,PHP也是如此。 在甚至开始编写第一行PHP代码之前,我们需要确保我们首先设置了正确的环境。 如今,名为Docker的工具使超级简单。

Docker is an application that creates different virtual environments. Most software development languages create images (essentially blueprints) that sets everything you’d need to start coding away behind the scenes for you. Here’s PHP Docker Image. After you check that out, we’ll need to open up a terminal window and set it up like so:

Docker是创建不同虚拟环境的应用程序。 大多数软件开发语言都会创建图像(本质上是蓝图),这些图像设置了您开始为幕后编码所需的一切。 这是PHP Docker映像 。 签出后,我们需要打开一个终端窗口并按如下所示进行设置:

Image for post

In the same terminal window you can then open an interactive instance of PHP:

然后,可以在同一终端窗口中打开PHP的交互式实例:

Image for post

This is useful if you’d like to write a few lines of PHP code and see how the language behaves. We need to take things a step further though if you have hopes of one day mastering this language!

如果您想编写几行PHP代码并查看该语言的行为,这将非常有用。 如果您希望有一天掌握这种语言,那么我们需要采取进一步的措施!

Docker撰写 (Docker Compose)

Before we get started with Docker Compose, we need to add the following line:

在开始使用Docker Compose之前,我们需要添加以下行:

0.0.0.0 docker.local

to our hosts file. Instructions for how to do this on all major systems are located here.

到我们的主机文件。 有关在所有主要系统上执行此操作的说明,请参见此处

Now, create a new project folder, I’m going to call mine my-first-php (mine is inside my blog working directory, it’s ok for yours to start at my-first-php). Inside it we’ll need the following directories:

现在,创建一个新的项目文件夹,我将其命名为my-first-php (mine在我的博客工作目录中,可以从my-first-php )。 在其中,我们需要以下目录:

Image for post

Now you’ll need to create these 3 files (full path shown so that you know where to place them):

现在,您需要创建以下3个文件(显示了完整路径,以便您知道将它们放置在何处):

1. my-first-php/docker-compose.yml

1. my-first-php / docker-compose.yml

2. my-first-php/.docker/php/Dockerfile

2. my-first-php / .docker / php / Dockerfile

3. my-first-php/.docker/nginx/site.conf

3. my-first-php / .docker / nginx / site.conf

Once those files are in place, open up your terminal and run this command:

这些文件放置到位后,打开终端并运行以下命令:

docker-compose up –build

A bunch of text should fly by. When everything ultimately settles you should see something similar to this:

一堆文字应该飞过去。 当一切最终解决后,您应该会看到类似以下内容:

Image for post

Now open up a separate terminal window and type the following command:

现在打开一个单独的终端窗口,然后键入以下命令:

docker exec -it php bash

You should see a screen like this:

您应该看到这样的屏幕:

Image for post

What we’ve done above is akin to SSH’ing into a remote server running PHP. Try typing in php -a and you’ll see that it brings up PHP’s interactive shell again!

上面我们完成的工作类似于SSH进入运行PHP的远程服务器。 尝试输入php -a ,您将看到它再次弹出PHP的交互式外壳!

Image for post

If you were to go to http://docker.local you should see:

如果要转到http://docker.local ,则应该看到:

Image for post

This means that NGINX is responding to our local HTTP request. However, we configured it to look for an index.html or index.php file as the main entry-point for our application. So let’s set that up real quick:

这意味着NGINX正在响应我们的本地HTTP请求。 但是,我们将其配置为寻找index.html或index.php文件作为我们应用程序的主要入口点。 因此,让我们快速进行设置:

Image for post

Reload your browser and…

重新加载浏览器并…

Image for post
Viola!
中提琴!

Getting this all set up is probably half of the battle, and I hope you’ve found these steps extremely simple to follow. From here I’d suggest installing a framework, because they’re full of code that I’ll describe in a section below that you must grasp if you hope to level-up your new found development skills!

完成所有这些工作可能只是成功的一半,我希望您发现这些步骤非常简单。 从这里开始,我建议安装一个框架 ,因为它们充满了我将在下面的部分中描述的代码,如果您希望提高新发现的开发技能,则必须掌握这些代码!

数据结构 (Data Structures)

This is the next most important area to master. When it comes to PHP, the Array is king. You have to learn what the difference is between a regular and an associative array. Then you should learn about multi-dimensional arrays. Finally, you should understand what a Stack and Queue are and how to construct and use them. Bookmark this page while you’re learning about all of this, you’ll thank me.

这是下一个最重要的领域。 当涉及到PHP时,Array为王。 您必须了解常规数组和关联数组之间的区别。 然后,您应该了解多维数组。 最后,您应该了解什么是堆栈和队列以及如何构造和使用它们。 在您了解所有这些的同时, 将此页面添加为书签,您将感谢我。

面向对象编程(OOP) (Object Oriented Programming (OOP))

The very first folks that started writing PHP code had no choice but to code in a style known as procedural programming. For a characterization of what that means, picture an entire application running line-by-line in a single file. This might not seem like the worst thing in the world, but do it for any length of time and soon you’ll discover all the problems involved with this approach. Some of the biggest were that there was no code-reusability (unless you consider that to be copy-and-paste), variables were in a global scope and could be altered at any point of your script’s execution (making it very difficult to trace down exactly where that would occur), and you had to ensure that any files you needed were properly loaded at the very start of your script (otherwise your script would just stop executing).

最早开始编写PHP代码的人们别无选择,只能以一种称为过程编程的方式进行编码。 为了说明这意味着什么,请在单个文件中逐行运行整个应用程序。 这看起来似乎不是世界上最糟糕的事情,但是只要经过一段时间,它就会很快发现所有与该方法有关的问题。 最大的一些错误是没有代码可重用性(除非您认为是可复制和粘贴的),变量在全局范围内,并且可以在脚本执行的任何时候进行更改(这使得跟踪非常困难)准确记录下来的位置),并且必须确保在脚本开始时正确加载了所需的所有文件(否则脚本将停止执行)。

Implementing OOP in your PHP project resolves these issues and more! So it is important that you learn about what it is and how to use it. The sooner you master this concept, the sooner you’ll be writing flawless, reusable, resilient code!

在您PHP项目中实现OOP解决了这些问题以及更多问题! 因此,重要的是要了解它是什么以及如何使用它 。 越早掌握这个概念,就越早编写完美,可重用,有弹性的代码!

关系数据库管理系统(RDBMS) (Relational Database Management System (RDBMS))

You should learn about what an RDBMS is, and how to use SQL. PHP integrates with a few different RDBMS’s of which MySQL, PostgresSQL, and MariaDB are probably the most well-known and supported. They each have their own set of strengths and weaknesses, as well as their own flourishes (or quirks) for their SQL. You should look into what those differences are before deciding which one you like best. The docker-compose.yml file above utilizes MySQL because that’s what I’m most familiar with but can be easily replaced with whichever system you like best.

您应该了解什么是RDBMS ,以及如何使用SQL 。 PHP与几种不同的RDBMS集成在一起,其中MySQLPostgresSQLMariaDB可能是最著名和受支持的。 他们每个人都有自己的优点和缺点,以及他们自己SQL蓬勃发展(或怪癖)。 在决定最喜欢哪一个之前,您应该先研究一下这些差异。 上面docker-compose.yml文件利用了MySQL,因为这是我最熟悉的,但是可以很容易地用您最喜欢的任何系统替换。

No matter which system you end up using, some of the key concepts to understand are SELECT, JOIN (INNER, LEFT, OUTTER, FULL), and GROUP BY statements. Before that you’ll need to familiarize yourself with and use INSERT INTO, UPDATE and DELETE statements. Finally, you’ll need to understand what PDO is and how PHP uses it to talk to the database system.

无论最终使用哪种系统,都需要理解的一些关键概念是SELECTJOIN ( INNERLEFTOUTTERFULL )和GROUP BY语句。 在此之前,您需要熟悉并使用INSERT INTOUPDATEDELETE语句。 最后,您需要了解什么是PDO ,以及PHP如何使用它与数据库系统进行通信。

结论 (Conclusion)

You don’t need to learn about these topics in any particular order. But you must get the hang of each one if you have any hopes of becoming a PHP developer, let alone a software developer. Once you get the basics, you’ll find it’s almost as easy as learning to ride a bike!

您无需按任何特定顺序来学习这些主题。 但是,如果您有希望成为PHP开发人员的希望,更不用说软件开发人员了,您必须牢牢抓住每一个人。 一旦掌握了基础知识,您就会发现它几乎像学习骑自行车一样简单!

As promised, where I think you should go from here:

如所承诺的,我认为您应该从这里出发:

  • Learn about HTML and JavaScript, and how the latter can alter the former

    了解HTML和JavaScript,以及后者如何改变前者
  • Version/Source Control with Git

    使用Git的版本/源代码控制
  • Understanding what HTTP requests are and what a RESTful API is

    了解什么是HTTP请求以及什么是RESTful API
  • Everything should culminate with understanding what MVC and SPA mean, and how to build them

    一切都应以理解MVC和SPA的含义以及如何构建它们为最终

I plan to continue writing about ways to learn about all these different technologies and what you should focus on when you do, so if this interests you make sure to give me a follow on Medium and Twitter!

我计划继续撰写有关学习所有这些不同技术的方法,以及在学习时应该关注的重点,因此,如果您对此感兴趣,请确保在MediumTwitter上给我一些关注!

If you have any questions, comments, or concerns please reach out!

如果您有任何疑问,意见或疑虑,请与我们联系!

翻译自: https://medium.com/swlh/how-to-learn-php-4fb96a58a5f4

如何学习php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值