CakePHP Coding Guidelines: Why are some properties camelCased instead of CamelCased? [closed]

StackOverflow https://stackoverflow.com/questions/23390857

  •  12-07-2023
  •  | 
  •  

Domanda

Just a quick question:

When looking to Controller.php:

What's the underlying coding convention for property-names? I always thought, that properties, which reference a object starts with a uppercase letter, whereas basic properties, referencing booleans/strings/ints, starts with a lowercase letter.

But, in Controller.php, there are:

public $request; // referencing an instance of a CakeRequest object public $View; // referencing an instance of a View

So, where's the difference?

È stato utile?

Soluzione

The general rule regarding variable and property casing is:

Normal variables should start with a lowercase letter, and should be written in camelBack in case of multiple words. Variables containing objects should start with a capital letter

As such your understanding is correct.

There are however some inconsistencies for/from:

  • Backwards-compatibility
  • Multiple developers, some more consistent than others
  • Mistakes =)

Altri suggerimenti

The reason they differ is changing opinion over time I guess. When CakePHP had relatively few objects internally it made sense to call them out with CamelCase names. However, over time we've added more objects, and in some cases like request wanted to avoid potential issues with userland code that may make Request. On top of these is the need to not break compatibility needlessly.

My current thinking is that framework internal objects, or non-userland objects will be camelBacked, while userland objects like Tables, Components, Tasks, Helpers etc are CamelCased.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top