I am doing lots of programming in Symfony 2, the PHP framework. When I program in Python, I don’t have much trouble keeping my lines up to 79 characters long, but when I program in PHP, especially in Symfony with its long bundle names, I find it very difficult to maintain the 79 character line width and keep the code nice looking and easy to follow at the same time. For example, the code below is very difficult to wrap to 79 characters and keep it “nice”.
return $this->render('MyDemoCodeVendorBundle:Default:preregister_service_vendor.html.twig', array('form' => $form->createView()));
Do you have any suggestions/style recommendation as to how to format the code for this rather short line width? Thank you!
I’d suggest using a widely accepted standard like PSR-2: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md . There are a few examples on that page that deal with long lines. PSR-2 suggests a “soft” limit of 120 characters, rather than your preference for 79 characters, but by following their guidelines, I would write the line like this:
That gives you 75 characters max, assuming 4 space indentation.