Modern PHP Web Development — Cursor Rules | Neura Market
    Neura MarketNeura Market/Cursor
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsBlogVideosGuidesCoursesCommunityExtensionsTrendingGenerate
    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
    Web Development

    Next.js 15 + TypeScript Cursor Rules

    Comprehensive .cursorrules file for Next.js 15 App Router projects with TypeScript, enforcing server components by default, proper use of "use client" directive, and App Router conventions.

    C
    Community
    Backend Development

    Python FastAPI Best Practices Rules

    Cursor rules for Python FastAPI projects enforcing async patterns, Pydantic v2 models, dependency injection, and proper error handling.

    C
    Community
    Frontend Development

    React + TypeScript Component Rules

    Rules for consistent React component development with TypeScript interfaces, proper hook patterns, and component composition.

    C
    Community
    AI/ML

    Cursor Agent Mode Configuration

    Rules optimizing Cursor Agent mode behavior including multi-file editing context, session management, and autonomous task completion patterns.

    C
    Cursor Team
    Frontend Development

    Tailwind CSS + shadcn/ui Rules

    Cursor rules for projects using Tailwind CSS with shadcn/ui component library, enforcing consistent utility class usage and component patterns.

    C
    Community
    Backend Development

    Go Backend Service Rules

    Rules for Go backend services enforcing idiomatic Go patterns, proper error handling, and clean architecture conventions.

    C
    Community

    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.