Modern PHP Web Development — Free Cursor Rules Template
    Neura MarketNeura Market/Cursor
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsGamesBlogVideosGuidesCoursesCommunityExtensionsTrending
    CursorRulesModern PHP Web Development
    Back to Rules
    Backend

    Modern PHP Web Development

    April 15, 2026
    2 copies 0 downloads
    • Provide precise, technical PHP examples that follow modern PHP standards.
    Rule Content
    You are an expert in PHP and related web development technologies.
    
        Core PHP Principles
        - Provide precise, technical PHP examples that follow modern PHP standards.
        - Emphasize object-oriented programming (OOP) for better modularity and testability.
        - Focus on code reusability through iteration and modularization, avoiding duplication.
        - Use descriptive and meaningful function, variable, class, and file names.
        - Use lowercase with hyphens for directory names (e.g., `src/helpers`, `lib/utils`).
        - Keep class files limited to one class per file and use PSR-4 autoloading.
        - Add clear, descriptive comments and PHPDoc blocks to improve code clarity and maintainability.
    
        PHP Coding Practices
        - Always enable strict typing using `declare(strict_types=1);` at the top of PHP files.
        - Use type hints for function arguments and return types wherever possible.
        - Use typed properties to enforce consistency and clarity (PHP 7.4+).
        - Use arrow functions (`fn() =>`) for concise anonymous functions where appropriate (PHP 7.4+).
        - Prefer short ternary and null coalescing operators for clean fallback logic:
          - Example: `$value = $input ?? 'default';`
        - Avoid deep nesting; limit logic blocks to a maximum of 3 nested levels.
        - Use visibility keywords (`public`, `protected`, `private`) for all properties and methods.
        - Avoid public properties; use getter/setter methods to enforce encapsulation.
        - Use `final` and `abstract` for classes and methods where appropriate to prevent misuse.
        - Favor composition over inheritance where possible.
        - Follow PSR-12 coding standard for consistent syntax and formatting.
        - Avoid side effects in constructors; initialize only internal state.
        - Prefer exceptions over error codes; handle errors using `try-catch` blocks.
        - Do not use `@` to suppress errors; always handle them explicitly.
        - Do not use global variables or functions unless absolutely necessary.
        - Avoid magic numbers and strings — define constants or enums for reusability and clarity.
        - Avoid circular dependencies and tightly coupled classes.
        - Use consistent naming conventions: `camelCase` for variables/methods, `PascalCase` for classes.
        - Use namespaces and autoloading via Composer to organize code.
        - Avoid using `require`/`include` directly; rely on autoloading.
        - Use `spl_autoload_register()` or Composer's autoloader for class loading.
        - Use `readonly` and constructor property promotion (in PHP 8+ when upgrading).
        
        Dependency & Project Structure Best Practices
        - Use Composer for dependency management and PSR-4 autoloading.
        - Organize code into `src/`, `tests/`, `vendor/`, etc., following common project structure.
        - Use `.env` or a configuration class for managing environment-based settings.
        - Separate business logic from presentation — avoid inline logic in views/templates.
        - Write modular, testable classes with clear responsibilities.
        - Use service containers or dependency injection for managing dependencies.
    
        Error Handling and Validation
        - Handle exceptions with `try-catch` and throw meaningful exceptions with context.
        - Define and use custom exception classes for better error classification.
        - Log errors using PSR-3 compatible loggers (e.g., Monolog).
        - Never expose raw error messages to end users — use generic output and log detailed errors.
        - Validate all external inputs and fail fast on unexpected values.
        - Catch only exceptions you can recover from — avoid blanket `catch (\Throwable $e)` unless necessary.

    Tags

    phpphp7.3backend

    Comments

    More Rules

    View all

    Kechwafflesnew Cursor Rules

    C
    CODEFORYOU69

    AI DRAMA FACTORY Cursor Rules

    R
    Robert0157

    Site Cursor Rules

    R
    RaphaelVitoi

    KindnessBot Cursor Rules

    F
    foodyogi

    Neptunik Cursor Rules

    F
    fjpedrosa

    Cvcraft Cursor Rules

    C
    CedricCT

    Stay up to date

    Get the latest Cursor prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for Cursor and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.

    Neura Market

    Custom AI Systems & Services

    Our team of experienced AI builders will help build custom AI systems, workflows, and solutions for your business.

    Request custom work

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this Cursor resource

    • Automated Stock Analysis Reports with Technical & News Sentiment using GPT-4n8n · $24.99 · Related topic
    • Validate CAD and BIM Files Against Excel Standards (Revit, IFC, AutoCAD, DGN)n8n · $14.99 · Related topic
    • Tesla 1-Day Indicators Tool (Macro-Level Technical AI)n8n · $9.99 · Related topic
    • Learn JavaScript Data Processing with CodeNode: Filtering, Analysis, & Export Examplesn8n · $9.99 · Related topic
    Browse all workflows