Giter Site home page Giter Site logo

trait代码复用机制问题 about doc-zh HOT 5 CLOSED

php avatar php commented on September 28, 2024
trait代码复用机制问题

from doc-zh.

Comments (5)

mowangjuanzi avatar mowangjuanzi commented on September 28, 2024

如果你想实现,不同的类包含不同的实例,也就是你期望的结果。

那么你只需将 trait 中的 protected static $instance = null; 修改为 private static $instance = null; 即可。

from doc-zh.

mowangjuanzi avatar mowangjuanzi commented on September 28, 2024

补充下,这个问题是属性继承问题。只有 设置为 private 的时候,每个类的属性才会不同。具体可以看下相关可访问性不同导致的变化。

from doc-zh.

vscing avatar vscing commented on September 28, 2024

@mowangjuanzi 正常的类里面,父类中的属性被子类重写了。但是用trait提取公共部分,并没有被重写。

from doc-zh.

vscing avatar vscing commented on September 28, 2024

@mowangjuanzi php/php-src#10937 辛苦看看这个是否是调整

from doc-zh.

sy-records avatar sy-records commented on September 28, 2024

Duplicate of php/php-src#10935
Fixed via php/php-src@9a250cc

这个实现会在 PHP 8.3 中包含。

from doc-zh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.