Skip to content
Advertisement

Tag: annotations

Annotations: How to specify timestamps in docblocks in php

I have a mehtod that returns timestamps. I want to do something like this: However, I don’t think @return array<int, timestamp> is valid. What is the valid format for specifying timestamps in docblocks? Answer You can use int[], there is no valid value for timestamps. You can however create a ValueObject. If you use a value object:

PHP 8 Attributes: Is it possible to validate metadata passed to attributes or force attribute instantiation?

Playing a little bit with the new PHP 8 attributes (annotations) (https://stitcher.io/blog/attributes-in-php-8) I started to create my own ones. Simple example: Hoping that the following code would throw an BadAttributeMetadataException unfortunately it finishes successfully: Is there away to validate the metadata passed for (custom) attributes? Most probably the attributes have to be instantiated automatically somehow. Answer Everything is possible –

How to autoload custom annotation classes without using AnnotationRegistry?

I’m using Doctrine Annotations library (not the whole Doctrine, only annotations) and want to make a custom annotation class. composer.json: index.php: entities/MyClass.php annotations/TestAnnotation.php It gives me the following error: The only solution i found on the Internet is to use AnnotationRegistry::registerLoader or something similar, but it is deprecated so i’d like to solve the problem in another way. Answer One

Annotations in Symfony 4

I try to develop with Symfony 4 so I follow the tutorial on symfony.com I’ve got an error when I try to access at : This is the error : [Syntax Error] Expected PlainValue, got ”’ at position 7 in method AppControllerHomeController::home() in /Users//Documents/ProjetSymfo4/my-project/config/routes/../../src/Controller/ (which is being imported from “/Users//Documents/ProjetSymfo4/my-project/config/routes/annotations.yaml”). Make sure annotations are installed and enabled. I already ran

Advertisement