php注解
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">目的</span></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">认识</span>和<span style="color: black;">运用</span>php注解,<span style="color: black;">倘若</span>你<span style="color: black;">已然</span><span style="color: black;">把握</span>其他一种<span style="color: black;">拥有</span>注解的语言,例如:java、python等,你在本文中只需要<span style="color: black;">认识</span>点语法就行。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">示例</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php8以前的版本,注解写在注释里,<span style="color: black;">倘若</span>你<span style="color: black;">把握</span>其他语言的注解,你是不是感到很奇怪,有点难以接受,我<span style="color: black;">亦</span>是。它的原理是运行时<span style="color: black;">经过</span>反射来解析和处理的,和java的运行时注解一样原理。将来我会在写一篇自定义php注解并<span style="color: black;">运用</span>的<span style="color: black;">文案</span>。</p><span style="color: black;"><span style="color: black;"><?php</span>
<span style="color: black;">/**
* <span style="color: black;">@DataType</span>(
* id = "example_color",
* label = "Color",
* constraints = {},
* definition_class = "\Drupal\example\TypedData\ColorDefinition"
* )
*/</span>
<span style="color: black;"><span style="color: black;">class</span> <span style="color: black;">Color</span> <span style="color: black;">extends</span> <span style="color: black;">Map</span> </span>{ }</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php8+版本写法</p><span style="color: black;"><span style="color: black;"><?php</span>
<span style="color: black;">#,</span>
definition_class:<span style="color: black;">"\Drupal\example\TypedData\ColorDefinition"</span>]
<span style="color: black;"><span style="color: black;">class</span> <span style="color: black;">Color</span> <span style="color: black;">extends</span> <span style="color: black;">Map</span> </span>{ }</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这般</span>是不是和java注解<span style="color: black;">同样</span>啦?尽管还有点别扭,<span style="color: black;">然则</span>php有他的优点,<span style="color: black;">咱们</span><span style="color: black;">亦</span>就接受它的不足。和其他语言<span style="color: black;">同样</span>,各有优缺点。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">总结</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">好了,本文只做个识别注解的<span style="color: black;">认识</span>。</p>
你的话深深触动了我,仿佛说出了我心里的声音。 可以发布外链的网站 http://www.fok120.com/ 楼主节操掉了,还不快捡起来!
页:
[1]