PHP Cursor Rules

Learn about cursor rules specific to PHP development.

PHP-Specific Rules

Cursor rules in PHP enhance your coding experience by providing smart navigation and manipulation features tailored for PHP development.

Code Navigation

  • Navigate between class definitions and implementations
  • Jump through namespace declarations and use statements
  • Quick access to method declarations and trait implementations
  • Smart navigation through PHP's superglobals ($_GET, $_POST, etc.)

Smart Selection

  • Select complete PHP tag blocks (<?php ... ?>)
  • Expand selection to include heredoc and nowdoc syntax
  • Smart selection of array syntax (both array() and [])
  • Select complete namespace blocks

Code Manipulation

  • Quick method and property visibility changes (public, private, protected)
  • Automated trait usage and implementation
  • Smart array manipulation features
  • PSR standard compliance helpers

Best Practices

  • Use namespace-aware navigation for better code organization
  • Leverage PHP-specific syntax features
  • Utilize object-oriented programming patterns effectively

Examples

// Navigate through namespace declarations
namespace App\Controllers;

use App\Models\User;
use App\Services\AuthService;

// Class and method navigation
class UserController
{
    private $authService;

    public function __construct(AuthService $authService)
    {
        $this->authService = $authService;
    }

    public function index()
    {
        $users = User::all();
        return $users;
    }
}

// Trait implementation
trait Loggable
{
    public function log($message)
    {
        // Logging implementation
    }
}

Configuration

Customize PHP-specific cursor rules in your settings:

{
  "php.cursorRules": {
    "namespaceNavigation": true,
    "smartSelection": true,
    "traitHandling": true,
    "psr": {
      "autoformat": true,
      "compliance": "psr-12"
    }
  }
}