Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Coding standard
  • Hi guys,
    I'm learning FuelPHP from scratch again... Last time I opened the docs for a site for 2 or 3 version ago, so I want to study it again, making my code elegant and useful.

    Reading the documentation I've a question regarding the codind standard: the (unofficial) PHP world is moving to some coding standards described here: they cover autoload, naming convenction, brace position and more.

    I know that the code structure doesn't make the application working better, but I'm curious about what you suggest for a new application, since the FuelPHP standard are quite different.


    FIG EXAMPLE:
    <?php
    namespace
    Vendor\Package;

    class Foo extends Bar implements FooInterface
    {
    public function sampleFunction($a, $b = null)
    {
    if ($a === $b) {
    // body
    } elseif ($a > $b) {
    // body
    } else {
    // body
    }
    }

    final public static function bar()
    {
    // method body
    }
    }

    FUELPHP EXAMPLE:
    <?php
    namespace
    Vendor\Package;

    class Foo extends Bar implements Foo_Interface
    {
    public function sample_function($a, $b = null)
    {
    if ($a === $b)
    {
    // body
    }
    elseif ($a > $b)
    {
    // body
    }
    else
    {
    // body
    }
    }

    final public static function bar()
    {
    // method body
    }
    }
    Thanks!
  • HarroHarro
    Accepted Answer
    In general, we will keep the current coding standards, but for Fuel v2 some things are going to change:
    - full support for PSR-0 and PSR-1 ( and not for PSR-2 ! )
    - full support for composer, composer is used for the framework components too
    - PSR-4 autoloading for app code (everything inside the classes folder)
    - filenames will become case sensitive
    - filenames must be equal to the classname
    - snake_case to camelCase for method names

    So the example in Fuel v2 mode:
    <?php
    namespace Vendor\Package;

    class Foo extends Bar implements FooInterface
    {
        public function sampleFunction($a, $b = null)
        {
            if ($a === $b)
            {
                // body
            }
            elseif ($a > $b)
            {
                // body
            }
            else
            {
                // body
            }
        }

        final public static function bar()
        {
            // method body
        }
    }


    You can have a look at one of the repositories at https://github.com/fuelphp, which is the location of the upcoming v2 release.
  • Thanks you very much, really appreciate!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion