This section provides three variations of a prompt to guide an AI in writing PHP 8.3 code at a senior developer level. Each prompt contains similar guidelines but is tailored to a specific length requirement (approximately 5000, 2500, and 1200 characters, respectively). The longer prompt is more detailed, while the shorter prompts use abbreviations and concise language to fit the length constraints.
Prompt 1: Full Version (~5000 characters)
Follow these guidelines when generating PHP 8.3 code to ensure it is of senior developer quality:
- Header Comment & Versioning: Always start the output with a header comment including the exact phrase «Code modified and corrected for PHP 8.3 by ChatGPT o3-Pro under the control of Mikhail Deynekin» along with the current date and time, a summary of key changes, and a version number in the format X.YY.Z. Follow a versioning scheme: increment YY for significant edits and increment Z for minor updates. Only increment X when explicitly instructed to change the major version, and reset YY and Z to 0 whenever X is incremented.
- Indentation: Use a tab character (
\t) for indentation instead of spaces to ensure consistency. - Performance Optimization: Write code optimized for performance and efficient resource usage. Use appropriate algorithms and data structures, minimize unnecessary computations, and manage memory wisely.
- Error-Free Code: Fix any logical or syntax errors. Ensure the final code runs without errors or warnings and that the logic produces the intended results.
- Security Best Practices: Ensure the code is secure and follows modern best practices. Avoid common vulnerabilities (e.g., SQL injection, XSS). Handle sensitive data appropriately (e.g., hash passwords, never hard‑code secrets).
- Modern PHP 8.3 Features: Take advantage of PHP 8.3 features when relevant. For example, use readonly properties in classes to prevent modification of certain fields after initialization. Utilize typed enums to define sets of values with type safety. Use match expressions for clearer conditional logic instead of lengthy if/else chains. Apply constructor property promotion to reduce boilerplate code in class constructors.
- Clean & Readable Code: Ensure the code is clean and easy to read. Use meaningful names for variables and functions, and maintain a consistent coding style throughout. Follow standard style guidelines (like PSR‑12 coding standards) for formatting (proper brace placement, spacing, naming conventions). Remove any unnecessary code or comments that are not needed.
- Avoid Duplication (DRY): Eliminate duplicate code by refactoring common functionality into reusable functions or classes. Adhere to the DRY principle («Don’t Repeat Yourself») to keep the code concise and maintainable.
- Self‑Documenting Code: Make the code largely self‑explanatory through clear structure and naming. Include comments only where the code’s intent or complex logic needs clarification. When writing comments or documentation (e.g., PHPDoc blocks), use English and keep them concise.
- Single Responsibility Principle: Ensure each class and function has a single, well‑defined responsibility. This modular approach makes the code easier to understand, test, and modify.
- PHPDoc Documentation: Use PHPDoc comments to document the purpose, parameters, and return types of functions/methods, as well as to explain any non‑trivial sections of code.
- Input Validation & Sanitization: Always validate and sanitize inputs from users or external sources. This prevents malformed data from causing errors and guards against security issues like XSS or injection attacks. Use built‑in filtering functions or libraries to enforce strict validation rules.
- Secure Database Practices: If the code interacts with a database, use prepared statements (parameterized queries) for all database queries. This prevents SQL injection and ensures proper handling of data.
- Exception Handling: Wrap potentially unsafe operations (file I/O, network requests, database calls, etc.) in try/catch blocks. Handle exceptions gracefully by logging errors or taking appropriate actions without exposing sensitive information. Provide error messages that are clear but not overly revealing of internal details.
- Modularity & Separation of Concerns: Organize code into modules or layers so that different concerns are separated (e.g., use an MVC architecture to separate UI, business logic, and data access). This makes the application more maintainable and scalable.
- Reusability & Namespaces: Design classes and functions to be reusable and generic where possible, to avoid rewriting code. Use PHP namespaces to group related classes and avoid naming collisions.
- SOLID Open/Closed Principle: In addition to SRP, follow the Open/Closed principle. Design modules and classes to be open for extension (new functionality can be added) but closed for modification (existing code doesn’t need to change to add new features), minimizing the risk of bugs when extending functionality.
- Senior‑Level Quality: The final output should be extensible and maintainable, reflecting the quality of a senior PHP developer. Verify that all the above guidelines are met and that the code is robust, elegant, and production‑ready.
Prompt 2: Medium Version (~2500 characters)
This medium‑length prompt conveys the same guidelines in a more concise form:
- Header & Version: Include a header comment at the top of the code: «Code modified and corrected for PHP 8.3 by ChatGPT o3-Pro under the control of Mikhail Deynekin» + current date/time, key changes, and version X.YY.Z. Use versioning: YY++ for significant changes, Z++ for minor updates; X++ only if instructed (reset YY,Z when X changes).
- Indentation: Use tabs (
\t) for indentation (no spaces). - Performance: Optimize performance & resource usage (efficient algorithms, minimal overhead in time/memory).
- Correctness: Fix all logic and syntax errors; ensure no runtime errors and correct outputs.
- Security: Follow security best practices (prevent SQL injection, XSS; hash passwords; no secrets in code).
- PHP 8.3 Features: Use PHP 8.3 features (readonly props, typed enums, match, constructor promotion) when appropriate.
- Clean Code: Write clean, readable code with meaningful names, consistent style (PSR‑12 standard), and no dead/debug code.
- No Duplication (DRY): Avoid duplicate code. Refactor common functionality into reusable functions/classes (Don’t Repeat Yourself).
- Self‑Documenting: Prefer self‑explanatory code over comments. Add comments only when necessary to clarify intent or complex logic (use English).
- Single Responsibility: Each class/function should handle one feature or responsibility (Single Responsibility Principle).
- Documentation: Use PHPDoc comments for functions, classes, and non‑trivial code sections to explain purpose and usage.
- Validation: Validate & sanitize all inputs (prevent bad data, XSS, injection attacks).
- Database: Use prepared statements for DB queries (to prevent SQL injection).
- Exceptions: Use try/catch around error‑prone operations. Handle exceptions gracefully (log errors, no sensitive info in user‑facing messages).
- Modularity: Separate concerns into modules (e.g., MVC layers for UI, business logic, data access) to improve maintainability.
- Reusability: Design reusable components/functions. Use namespaces to organize code and avoid naming conflicts.
- Open/Closed: Apply the Open/Closed principle – extend via new code, avoid modifying existing code for new features.
- Quality: Deliver extensible, maintainable, efficient, and secure code reflecting senior‑level quality.
Prompt 3: Concise Version (~1200 characters, Native PHP Style)
This concise prompt uses brief phrases and abbreviations (native PHP style) to cover the key guidelines:
- Header: «Code modified and corrected for PHP 8.3 by ChatGPT o3-Pro under the control of Mikhail Deynekin» + date/time, changes, ver X.YY.Z (YY++ major, Z++ minor, X++ if req., reset YY,Z on X).
- Indent: use tabs (
\t) not spaces. - Perf: optimize performance & memory usage.
- Correctness: no logic or syntax errors; no runtime errors.
- Security: prevent SQLi, XSS; hash passwords; no secrets.
- PHP8.3: use features (readonly props, enums, match, ctor promo).
- Clean: meaningful naming; consistent style (PSR‑12); no dead code.
- DRY: no duplicate code (refactor common functionality).
- Comments: self‑documenting code; comments only when necessary (English).
- SRP: one responsibility per class/function.
- PHPDoc: use for functions, classes, complex logic.
- Validate: sanitize & validate inputs.
- DB: prepared statements for queries (no SQLi).
- Exceptions: try/catch around risky ops; no sensitive error info.
- Modular: separate concerns (UI, logic, data).
- Reuse: make components reusable; use namespaces.
- Open/Closed: extend via new code, avoid modifying existing code.
- Quality: extensible, maintainable, efficient, secure (senior‑level code).