草庐IT

构造器

全部标签

php - 特征中的构造函数定义如何冲突?

在PHP5.4.9中,以下示例触发了fatalerror“Bhascollidingconstructordefinitionscomingfromtraits”。traitT{publicfunction__construct(){echo__CLASS__.":constructorcalled.\n";}}classA{useT;}classBextendsA{useT;}当trait包含与构造函数不同的方法时没有问题,当构造函数实际复制到类中时也没有问题(不使用traits,即“语言辅助复制和粘贴”功能)。这里的构造函数有什么特别之处?PHP不应该能够弄清楚其中一个覆盖另一个吗

php - 向构造函数注入(inject)多个参数是不好的做法吗?

我正在开发一个相当复杂的物流管理系统,该系统将不断发展成为其他几个与ERP相关的模块。因此,我正在尝试尽可能多地采用SRP和开放/关闭原则,以便于扩展和基于域的管理。因此,我决定使用Laravel和以下模式(不确定是否有名称):我将使用PRODUCT对象作为示例。一个对象/实体/域有一个类类ProductService{}这个类有一个ServiceProvider,它包含在providers数组中,也是自动加载的:ProductServiceServiceProvider服务提供商实例化(制作)作为接口(interface)的ProductRepository。该接口(interfac

php - 您如何在 MVC 中构造和路由模块?

我正在构建一个MVC,其中一切都是模块。这将使我能够分离论坛和用户模块等对象的集合,以进一步组织我的MVC。/blog/controller/model/view/user/controller/model/view/forum/controller/model/view我目前将forum/edit/34之类的路由映射到包含Forum_Controller_Edit类的/forum/controller/edit.php.(这与所有操作都是ControllerForum_Controller::edit()的方法的标准方法略有不同)。这允许我将所有单独的“操作”分开将Controlle

php - 为 "$GLOBALS"构造的可变变量字符串在全局范围内工作,但不在函数范围内

Animportantnote:$GLOBALSaredirtyandevil.Don'tusethem.Ever.Nevereverever.Pleasefocusonthefactthatitdoesn'tworkandnotwhyyouwouldbedoingthisinthefirstplace,itispurelyatheoreticalquestionaboutatechnicalexercise.这是一个相当奇怪的。我正在尝试使用名为$GLOBALS的字符串构造一个可变变量。来自全局范围让我们看看在全局范围内使用var_dump()时会得到什么。$g=sprintf('%

php - 为什么 "Strict Standards"不适用于 PHP 构造函数?

这个问题在这里已经有了答案:WhydoesPHPallow"incompatible"constructors?(5个答案)关闭6年前。在现代版本的PHP(5.6以下)中,以下是无效程序error_reporting(E_ALL);classA{publicfunctionhello(X$one,Y$two){}}classBextendsA{publicfunctionhello(){}}interfaceX{}interfaceY{}$b=newB;PHP将拒绝运行它,而是给你一个类似下面的错误信息PHPStrictstandards:DeclarationofB::hello()

php - PHP 的 'unset' 构造在内部如何工作?

前言:我确实知道“未设置”在用户空间中是如何工作的,但我想了解它在内部是如何工作的。在zvalstructure上调用unset时,它会减少引用计数器(refcount__gc)。当refcount__gc达到0时,该变量不再使用,可以删除。问题是它是总是立即完成,还是在某些情况下可以稍后由垃圾收集器完成?我发现了两个相互矛盾的陈述:unset()doesjustwhatit'snamesays-unsetavariable.Itdoesnotforceimmediatememoryfreeing.PHP'sgarbagecollectorwilldoitwhenitseefits-b

java - SonarQube:java构造函数枚举中是否应该允许魔数(Magic Number)

关于规则鱿鱼:不应使用S109魔数(MagicNumber)Java中枚举的构造函数中不应该允许有数字吗?在我看来,下面的代码不应该违反规则。publicenumColor{RED(42),GREEN(123456),BLUE(666);publicfinalintcode;Color(intcolorCode){this.code=colorCode;}}我正在使用Sonarjava插件版本3.3 最佳答案 3.4版本会修复在SonarSource上查看此问题:http://jira.sonarsource.com/browse/

java - 内部/嵌套类构造函数的正确 "@link"或 "@see"javadoc 标记是什么?

我在让“@link”和“@see”标签为内部/嵌套类的构造函数工作时遇到了问题,希望这里有人能提供帮助。这个简短的示例类在第25行给出了javadoc警告,引用了“Layer()”文档前面几行中的“@link”和(等效的)“@see”标记。packagebogus;importjavax.swing.JPanel;publicclassLayeredPlotextendsJPanel{/***Constructorfortheplot.*/publicLayeredPlot(){}publicstaticclassLayer{privateStringname;/***Construc

java - Autowiring 构造函数时 Camel 没有路线

我在模块中使用springboot。我有一个包含多个子模块的父项目。当我使用ContructorAutowiring配置路由时,Camel路由无法启动。我得到Total0routes,其中0已启动当像这样启动构造函数时。privatefinalScanProcessorscanProcessor;privatefinalScheduleProcessorscheduleProcessor;privatefinalTagProcessortagProcessor;privatefinalLatestScanProcessorlatestScanProcessor;privatefinal

java - Java 转 Scala,如何处理调用父类(super class)构造函数?

问题摘要-如何将其转换为Scala类?问题-多个构造函数调用不同的super构造函数Java类-publicclassClassConstExampleextendsBaseClassExample{privateStringxyzProp;privatestringinType="def";privateStringoutType="def";privateStringflagSpecial="none";publicClassConstExample(finalStringfile,finalStringheader,finalStringinType,finalStringout