Posts Tagged: php

Symfony 2.8 Introduces the Range Form Element

The range form element is now available in Symfony 2.8. The range element is part of the HTML5 specification. In modern browsers, the range element is rendered as a slider. You can use it like this. $builder->add(‘volume’, ‘Symfony\Component\Form\Extension\Core\Type\RangeType’, [ ‘attr’ => [‘min’ => 0, ‘max’ => 11] ]); These go to eleven.

Handle XML Errors with PHP’s SimpleXMLElement

I don’t write procedural code any longer, so when I use PHP’s simple xml package, I use the object-oriented approach. Here’s how to handle, or suppress error/exceptions, when creating a SimpleXMLElement object. libxml_use_internal_errors(TRUE); // this turns off spitting errors on your screen try { $xml = new SimpleXMLElement($xmlStringOfData); } catch (Exception $e) { // Do… Read more »

Typing the Wrong Timezone in php.ini Creates Strange Issues

I’m not that type of programmer who remembers all of the mundane details associated with a given language. I rely heavily on the language documentation to get through my day. I just don’t have the bandwidth, or the desire to store in my brain, for instance, PHP’s timezone values. Even though I’ve been using one… Read more »

PHP 5.6 SoapClient verify_peer With Self-Signed Certificate

By default, PHP 5.6 has verify_peer enabled for openssl connections. So if you use the SoapClient to connect via SSL to a soap server, you’ll likely see “Could not connect to host” connection failures. To fix this, you need to generate some certificates on the server running your PHP applications and making the Soap calls…. Read more »

Symfony: Inject Repository rather than Entity Manager

Here’s a great blog post detailing how and why you should use repositories rather directly working with entities. http://php-and-symfony.matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager

Symfony Form Variables Reference

Here are the Symfony form variables. I’m posting it here because I find I often need to look at it and it’s easily to find here than in the Symfony documentation. Variable Usage form The current FormView instance. id The id HTML attribute to be rendered. name The name of the field (e.g. title) –… Read more »

List of Symfony2 Exceptions

Symfony/Component/OptionsResolver/Exception/MissingOptionsException.php Symfony/Component/OptionsResolver/Exception/OptionDefinitionException.php Symfony/Component/OptionsResolver/Exception/InvalidOptionsException.php Symfony/Component/Serializer/Exception/InvalidArgumentException.php Symfony/Component/Serializer/Exception/UnsupportedException.php Symfony/Component/Serializer/Exception/UnexpectedValueException.php Symfony/Component/Serializer/Exception/LogicException.php Symfony/Component/Serializer/Exception/Exception.php Symfony/Component/Serializer/Exception/RuntimeException.php Symfony/Component/HttpKernel/Exception/MethodNotAllowedHttpException.php Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php Symfony/Component/HttpKernel/Exception/HttpException.php Symfony/Component/HttpKernel/Exception/AccessDeniedHttpException.php Symfony/Component/HttpKernel/Exception/FlattenException.php Symfony/Component/Form/Exception/InvalidConfigurationException.php Symfony/Component/Form/Exception/TransformationFailedException.php Symfony/Component/Form/Exception/PropertyAccessDeniedException.php Symfony/Component/Form/Exception/TypeLoaderException.php Symfony/Component/Form/Exception/NotInitializedException.php Symfony/Component/Form/Exception/NotValidException.php Symfony/Component/Form/Exception/AlreadyBoundException.php Symfony/Component/Form/Exception/InvalidPropertyPathException.php Symfony/Component/Form/Exception/CreationException.php Symfony/Component/Form/Exception/StringCastException.php Symfony/Component/Form/Exception/FormException.php Symfony/Component/Form/Exception/TypeDefinitionException.php Symfony/Component/Form/Exception/UnexpectedTypeException.php Symfony/Component/Form/Exception/ErrorMappingException.php Symfony/Component/Form/Exception/InvalidPropertyException.php Symfony/Component/Process/Exception/ProcessFailedException.php Symfony/Component/Process/Exception/RuntimeException.php Symfony/Component/Yaml/Exception/DumpException.php Symfony/Component/Yaml/Exception/ParseException.php Symfony/Component/Filesystem/Exception/IOException.php Symfony/Component/HttpFoundation/File/Exception/AccessDeniedException.php Symfony/Component/HttpFoundation/File/Exception/FileNotFoundException.php Symfony/Component/HttpFoundation/File/Exception/UnexpectedTypeException.php Symfony/Component/HttpFoundation/File/Exception/UploadException.php Symfony/Component/HttpFoundation/File/Exception/FileException.php Symfony/Component/DependencyInjection/Exception/InvalidArgumentException.php Symfony/Component/DependencyInjection/Exception/ParameterNotFoundException.php Symfony/Component/DependencyInjection/Exception/LogicException.php Symfony/Component/DependencyInjection/Exception/OutOfBoundsException.php Symfony/Component/DependencyInjection/Exception/BadMethodCallException.php Symfony/Component/DependencyInjection/Exception/ServiceNotFoundException.php Symfony/Component/DependencyInjection/Exception/RuntimeException.php Symfony/Component/DependencyInjection/Exception/ServiceCircularReferenceException.php Symfony/Component/DependencyInjection/Exception/InactiveScopeException.php Symfony/Component/DependencyInjection/Exception/ParameterCircularReferenceException.php Symfony/Component/DependencyInjection/Exception/ScopeCrossingInjectionException.php Symfony/Component/DependencyInjection/Exception/ScopeWideningInjectionException.php Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php Symfony/Component/Config/Exception/FileLoaderLoadException.php Symfony/Component/Config/Definition/Exception/InvalidConfigurationException.php Symfony/Component/Config/Definition/Exception/ForbiddenOverwriteException.php… Read more »

PHPUnit –log-json is Broken, Here’s How to Fix It

For some reason, PHPUnit doesn’t produce valid Json when using the –log-json command-line option. The output looks like this. { “event”: “suiteStart”, “suite”: “TestAcme”, “tests”: 3 }{ “event”: “testStart”, “suite”: “TestAcme”, “test”: “TestAcme::testAcme1” }{ “event”: “test”, “suite”: “TestAcme”, “test”: “TestAcme::testAcme2”, “status”: “pass”, “time”: 1.85778188705, “trace”: [], “message”: “”, “output”: “t” }{ “event”: “testStart”, “suite”: “TestAcme”,… Read more »

Stop building shitty PHP web applications

I’m sort of active on Stackoverflow.com and I see so many stupid questions from people who know nothing about PHP trying to cobble together a pile of shit web application. I admit that nearly 20 years ago when I started working with PHP, I wrote some awful code, just wretched shit. But back then, everyone… Read more »