Log in | Back to darenet.org

Web Development

In This Guide:

DareNET Development Wiki - Web Development

This document outlines technical and style guidelines which are followed in website-darenet. Contributors should also follow these guidelines.

Spaces, Linebreaks and Identation

  • Use one tab for each level of indentation.
  • Use Unix linebreaks ("\n"), not MSDOS ("\r\n") or OS9 ("\r").
  • Use K&R style braces and spacing.
  • Put a space after control keywords like if and for.
  • Put a space after commas in argument lists.
  • Put a space around operators like =, <, etc.
  • Don't put spaces after function names.
  • Parentheses should hug their contents.
  • Generally, prefer to wrap code at 80 columns.

Case and Capitalization

  • Name variables and functions using lowercase_with_underscores.
  • Name classes using UpperCamelCase.
  • Name methods and properties using lowerCamelCase.
  • Use uppercase for common acronyms like ID and HTML.
  • Name constants using UPPERCASE.
  • Write true, false and null in lowercase.

Comments

  • Do not use "#" (shell-style) comments.
  • Prefer "//" comments inside function and method bodies.

PHP Language Style

  • Use "<?php", not the "<?" short form. Omit the closing "?>" tag.
  • Prefer casts like (string) to casting functions like strval().
  • Prefer type checks like $v === null to type functions like is_null().
  • Avoid all crazy alternate forms of language constructs like "endwhile" and "<>" (acceptable in templates).
  • Always put braces around conditional and loop blocks.

PHP Language Features

  • Use PHP as a programming language, not a templating language.
  • Avoid globals.
  • Avoid extract().
  • Avoid eval().
  • Avoid variable variables.
  • Prefer classes over functions.
  • Prefer class constants over defines.
  • Avoid naked class properties; instead, define accessors.
  • Use exceptions for error conditions.