Home >Backend Development >PHP Problem >Is php object-oriented or process-oriented?
PHP language can apply both process-oriented and object-oriented programming. In many programming languages, process-oriented and object-oriented can only be programmed with one of the two, but PHP The difference between the language and other programming languages is that we can freely choose or mix PHP process-oriented and PHP object-oriented.
Process-oriented programming adopts the strategy of exchanging time for space. Because in the early days, the computer configuration was low and the memory was small. How to save memory became the top priority, even if the running time was longer. With the development of hardware technology, hardware no longer becomes a bottleneck. On the contrary, issues such as better simulation of the real world and system maintainability have emerged, so object-oriented design emerged as the times require.
Currently, general application systems applied on PCs generally use object-oriented methods because they do not need to consider hardware limitations, but the system maintainability and other aspects are very demanding; while when there are memory limitations, The required embedded systems are mostly designed and programmed in a process-oriented manner.
Process-oriented programming:procedure-oriented programming
referred to as POP, which is a process-centered programming idea that analyzes the steps needed to solve a problem. Then use variables and functions to implement these steps step by step, and just call them one by one when using them.
Example:
$conn = mysql_connect('服务器名称', '数据库登陆名', '密码') or die('连接不成功!'); mysql_select_db('库名', $conn) or die('数据库不存在!'); $queryid = mysql_query("select * from sort"); while ($rs = mysql_fetch_assoc($queryid)) { echo $rs['name'];
Object-oriented programming: object oriented programming
referred to as OOP, is a The object concept is a programming paradigm and an abstract guideline for program development. It may contain data, properties, code and methods. Objects refer to instances of classes.
It takes the object as the basic unit of the program and encapsulates the program and data to improve the reusability, flexibility and scalability of the software. The program in the object can access and frequently modify the data associated with the object.
Recommended tutorial: PHP video tutorial
The above is the detailed content of Is php object-oriented or process-oriented?. For more information, please follow other related articles on the PHP Chinese website!