search
HomeBackend DevelopmentPHP TutorialMy PHP study notes (graduation project)_PHP tutorial

My PHP study notes (graduation project)_PHP tutorial

Jul 21, 2016 pm 03:20 PM
phpstudyapplicationpowerfulGraduation ProjectnotesSimpleClass libraryablegrammar

PHP has simple syntax, very good applications, and powerful class libraries. It can indeed write a very powerful server side. For someone like me who just needs a small server, it couldn't be better.
Simply speaking, when it comes to learning PHP, I think it’s better to read the manual. I spent a few days looking at the syntax. Because I have a programming foundation, it seems to be faster now. I just finished writing a simple server in PHP, for a purpose of course, to support the client of a ticket booking system. Below are my notes on the learning process. It would be nice to have a review in the future.
When there is no object of a certain class, you can call a method in a certain class through the scope discriminator (::);
When accessing a method in a base class, you can write parent::method() ;
 serialize() returns a string containing a byte stream representation of any value that can be stored in PHP.
unserialize() can use this string to reconstruct the original variable value.
Using serialization to save objects can save all variables in the object. The functions in the object are not saved, only the name of the class.
When serializing and deserializing the same object, you can use the definition file method that contains the same object.
This is because "new" does not return a reference by default, but returns a copy.
php5
Characteristics of classes and objects:
visibility: visibility
Attribute access limits: public: This attribute can be accessed anywhere,
protect derived classes or parent classes can access to this attribute, or an item within any class that defines this attribute)
private: only accessible within the class
A member declared as static can not be accessed with
an instantiated class object (though a static method can).
Static members and methods cannot be re-defined in subclasses.
(If a member is defined as static, then the member cannot be accessed by the instantiated object,
Static members cannot redefined in subclasses).
Static definition must be after accessing properties, such as: protect static
Static methods can be called without instantiation, so the $this parameter cannot be used when using static methods.
Static members cannot be accessed using ->.
constant: constant keyword, const is used to define immutable constants, and there is no need to use the $ symbol when defining.
The definition method is generally: const aconstant = 'constant';
The variables defined by glob in php are used throughout the page, including pages included in require and pages included in include.
Abstract class:
Abstract class cannot be instantiated. Any class with abstract methods must be defined as an abstract class.
If you inherit an abstract class, any abstract method in the abstract class must be overridden. The access limit of these methods can only be
the same as or lower than the access limit of the abstract parent class's methods.
Both abstract classes and abstract methods use abstract as the keyword.
 Object interface (object interface)
 Object interface allows you to specify which methods must be implemented, rather than letting you define which methods are captured.
 Object interface is defined using the interface keyword. It is a standard class, but none of its methods are implemented.
Any method in an interface object must be public, which is what interface objects must follow.
To implement an interface, you must use the implements mark, so the interface method implementation must be in a class. A class can implement multiple interfaces.
Overloaded:
Iterator:
Iterator can access all public object members in the class.
Implement the iterator interface in PHP5, which allows you to define how objects are accessed iteratively.
Design pattern:
Design pattern provides a good framework to implement some functional organization.
Factory pattern: Instantiate a required object during runtime.
Simple interest mode: The most obvious example is: database connection object. The following is an example of the best singleton pattern:
Singleton Function

Copy code The code is as follows:

    class Example
  {
  // Hold an instance of the class
  private static $instance;
  // A private constructor; prevents direct creation of object
  private function __construct()
  {
  echo 'I am constructed';
  }
  // The singleton method
  public static function singleton()
  {
  if (!isset(self::$instance)) {
  $c = __CLASS__;
  self::$instance = new $c;
  }
  return self::$instance;
  }
  // Example method
  public function bark()
  {
  echo 'Woof!';
  }
  // Prevent users to clone the instance
  public function __clone()
  {
  trigger_error('Clone is not allowed.', E_USER_ERROR);
  }
  }

  你还可以实现php5里面的iteratoraggregate接口对象来定义自己的迭代方法。
  魔术函数:
  The function names __construct, __destruct (see Constructors and Destructors),
  __call, __get, __set, __isset, __unset (see Overloading), __sleep, __wakeup,
  __toString, __clone and __autoload are magical in PHP classes.
  这些函数在存在于每一个php类中。你不要随意使用__来定义函数,除非你真的想这个函数具有魔术功能。
  __tostring()函数,这个函数将决定一个对象转换为字符的时候将发生的事。
  final关键字:
  final关键字用来阻止应用final关键字声明的类或者方法被继承,被覆盖。
  参数类型强制:
  可以在参数前面加上类名类控制传入的参数类型。
  require() 和 include() 除了怎样处理失败之外在各方面都完全一样。
  include() 产生一个警告而 require() 则导致一个致命错误。
  换句话说,如果想在丢失文件时停止处理页面,那就别犹豫了,用 require() 吧。
  require_once() 语句在脚本执行期间包含并运行指定文件。
  此行为和 require() 语句类似,
  唯一区别是如果该文件中的代码已经被包含了,
  则不会再次包含。有关此语句怎样工作参见 require() 的文档。
  PHP 有一个类型运算符:instanceof。instanceof 用来测定一个给定的对象是否来自指定的对象类。
  代码范例:
复制代码 代码如下:

  class A { }
  class B { }
  $thing = new A;
  if ($thing instanceof A) {
  echo 'A';
  }
  if ($thing instanceof B) {
  echo 'B';
  }
  ?>

  的 PHP 代码段结束标记可以不要,有些情况下当使用输出缓冲和
  include() 或者 require() 时省略掉会更好些。
  include() 就不是这样,脚本会继续运行。同时也要确认设置了合适的include_path。
  __CLASS__ :指的是当前类。
  异常处理,根据需要扩展异常处理类exception
  require()语句包含并运行指定文件;

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325147.htmlTechArticlephp语法简单,应用也非常好,而且类库强大,确实能写出很强大的服务器端。对于我这种只需要小功能服务器的人来说,再好不过了。 单纯...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)