PHP ?? (??) : ?? ? ??
PHP 8? ?? ? PHP ??? ???, ???, ??, ?? ?? ? ??? ?? ???? ???? ??? ??? ?????. ??? ?? ???? ???? ?? ?? ? PHPDOC ?? ?? ??? ? ????. ?? ??? ??? ????.
?? ?? :
??? ?? ??? ????? #[Attribute]
???? ???? ???? ?? ? ??? ??? ????? (? : TARGET_CLASS
, TARGET_METHOD
).
<code class="php">#[Attribute(Attribute::TARGET_CLASS)] class MyAttribute { public function __construct(public string $value) {} } #[MyAttribute('example')] class MyClass { // Class implementation }</code>
?? ? ?? :
??? ???? ???? ??? ?? ? ? ????.
<code class="php">$reflectionClass = new ReflectionClass(MyClass::class); $attributes = $reflectionClass->getAttributes(MyAttribute::class); foreach ($attributes as $attribute) { $instance = $attribute->newInstance(); echo $instance->value; // Outputs: example }</code>
PHP ??? ??? ?? ???? ?? ?? ???? ???? ? ?????
PHP ??? ?? ?? ???? ?? ??? ? ?? ??? ??????.
?? ?? :
??? PHPDOC ??? ???? ????? ?? ?? ??? ?????. ??? PHP ?? ??? ????? ???? ??? ?? ???? ??? ??? ?? ???? ???? ?? ???? ?? ??? ? ????.
<code class="php">// Less readable PHPDoc comment /** * @Route("/example") */ class MyClass {} // More readable attribute #[Route('/example')] class MyClass {}</code>
?? ? ?? ?? :
??? ????? ??? ?? IDE? ?? ?? ? ?? ??? ???????. ??? ??? ??? ?? ???? ??????.
?? ?? ??? :
??? ???? ?? ???? ? ? (??? ??)?? ?? ? ? ???? ?? ?? ? ??? ????. ? ?? ???? ???? ???? ??? ?????? ?? ?? ? ??????.
??? ?? ? ??????? ?? :
?? ?? PHP ??? ?? ? ?????? ?? ???? ?? ? ??? ????? ???, ??, ??? ?? ??? ??? ? ????.
?? ?? ?????? PHP ??? ???? ???? ?? ??????
PHP ??? ??? ?? ?????? ??? ? ????.
? ??? ????? ??? :
Laravel ?? Symfony? ?? ??? ???? ??? ???? ???? ???? ??? ?? ???? ??? ??? ???? ?? ???? ???? ? ????.
<code class="php">use Symfony\Component\Routing\Annotation\Route; class BlogController { #[Route('/blog/{slug}', name: 'blog_show')] public function show(string $slug): Response { // Implementation } }</code>
??:
??? ??? ?? ?? ??? ?? ???? ??? ???? ???? ????? ??? ? ? ????.
<code class="php">use Symfony\Component\Validator\Constraints as Assert; class User { #[Assert\NotBlank] #[Assert\Email] public $email; }</code>
??? :
API?? ??? ??? JSON ?? ?? ???? ????? ??? ?? ? ? ????.
<code class="php">use JMS\Serializer\Annotation as Serializer; class Product { #[Serializer\SerializedName('product_id')] public $id; #[Serializer\Exclude] public $internalData; }</code>
?? ??:
??? ???? ?? ??? ???? ? ??? ? ???, ? : ?? ???? ?? ????? ? ?? ????
<code class="php">use App\Logging\Annotation\Loggable; class UserService { #[Loggable(level: 'info')] public function createUser(User $user): void { // Implementation } }</code>
PHP ??? ???? ??? ??? ??? ? ????. ???? ?????????
?, PHP ??? ???? ??? ??, ?? ?? ?? ??? ???? ?? ??? ???? ??? ? ????. ?? ? ??? ??? ??? ????.
??? ????? ?? ?? :
??, ??? ?? ?? ??? ???? ? ??? ?? ???? ??????.
<code class="php">#[Attribute(Attribute::TARGET_PARAMETER)] class Inject { public function __construct(public string $service) {} }</code>
?? ?? :
?? ?? ??? ?? ?? ?? ??? ?? ??? ??? ???? ?? ???? ???? ?????.
<code class="php">class UserService { private $logger; public function __construct( #[Inject('LoggerInterface')] LoggerInterface $logger ) { $this->logger = $logger; } public function createUser(User $user): void { $this->logger->info('Creating user'); // Implementation } }</code>
?? ?? :
?????, ??? ??? ???? ??? ???? ?? ? ??? ??? ?? ????? ?????. ????? ?? ??? ?? ??? ? ?? ??? ????.
<code class="php">class Container { public function get($className) { $reflectionClass = new ReflectionClass($className); $constructor = $reflectionClass->getConstructor(); if (!$constructor) { return new $className; } $parameters = $constructor->getParameters(); $dependencies = []; foreach ($parameters as $parameter) { $attribute = $parameter->getAttributes(Inject::class)[0] ?? null; if ($attribute) { $injectAttribute = $attribute->newInstance(); $dependencies[] = $this->get($injectAttribute->service); } else { $dependencies[] = $this->get($parameter->getType()->getName()); } } return $reflectionClass->newInstanceArgs($dependencies); } }</code>
? ??? Container
???? ??? ???? ??? ?? ?? ? ?? ??? ?????. Inject
??? ???? ??? ???? ???? ? ????? ?????.
??? ?? ??? ???? ????? ???? ??? ?? ? ? ????? ??? ???? ???? ???? ??? ??? ? ????. ? ???? ??????? ???? ?? ??? ??????.
? ??? PHP ?? (??) : ?? ? ??.? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??









