PHP / Magento Dev Blog

  • Publikacje
  • O autorze
  • Kontakt

AI tools for the PHP developer – Copilot, Claude, Ollama, where it helps and where it fails

by Henryk Tews / Tuesday, 02 April 2024 / Published in PHP

AI coding assistants moved from novelty to daily tool in the span of a year. After using GitHub Copilot, Claude, and local models via Ollama for several months across PHP and Magento projects, I have a clear picture of where they genuinely save time and where they confidently generate plausible-looking wrong code. This is an honest assessment, not a marketing piece.

What I actually use and for what

Tool Use case Verdict
GitHub Copilot Inline completion while writing code Good for boilerplate and repetitive patterns
Claude Code review, architecture questions, explaining errors Best for reasoning about code
Ollama (local) Code work with NDA / sensitive data Good, slightly behind cloud models
ChatGPT Quick questions Decent, replaced by Claude for code

Where AI genuinely helps – concrete examples

<?php

// 1. BOILERPLATE: Writing a new Magento 2 module skeleton
// Copilot knows the file structure and fills it in fast
// module.xml, registration.php, di.xml - tedious but predictable

// 2. TEST GENERATION: "Write PHPUnit tests for this service"
// Prompt + existing class = good test scaffold in seconds
// I still review and fix edge cases but the scaffolding saves 15+ minutes

// 3. REGEX: "Match this date format but not that one"
// AI is better at regex than I am, reliably

// 4. DOCBLOCKS: "Write PHPDoc for this method"
// Fast, accurate, consistent

// 5. EXPLAINING ERRORS
// Paste a 30-line Magento DI exception stack trace
// AI explains which class failed to instantiate and why
// Much faster than reading the trace manually

class MyMagentoService
{
    // Copilot suggested this entire constructor from just the class name and context
    public function __construct(
        private \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
        private \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
        private \Psr\Log\LoggerInterface $logger
    ) {}
}

Where AI fails – be careful

<?php

// 1. MAGENTO VERSION-SPECIFIC CODE
// AI often generates code that was correct in Magento 2.2 but deprecated in 2.4
// Always check the Magento version before trusting the output

// AI might generate:
$product->load($id); // Deprecated since 2.1!

// Should be:
$product = $productRepository->getById($id);

// 2. THIRD-PARTY MODULE INTEGRATION
// AI has no knowledge of specific module versions or vendor-specific APIs
// "Integrate with [obscure module]" generates confident nonsense

// 3. COMPLEX BUSINESS LOGIC
// AI can implement a simple rule correctly
// Multi-step rules with edge cases - always wrong in some case
// Example: "calculate price with tiered discounts, minimum order, and coupon stacking"
// The AI gives you something that looks right but fails on the edge case

// 4. SECURITY-SENSITIVE CODE
// AI generates SQL injection vulnerabilities, missing input validation
// Never trust AI-generated code for:
// - User input handling
// - Authentication/authorisation
// - Payment processing
// - File upload handling

// 5. HALLUCINATED APIS
// "Use the MagentoXyz::doThing() method to..." - that method does not exist
// AI confidently invents method names that do not exist
// Always verify against actual Magento source or documentation

Practical workflow – where AI fits

# My actual workflow in a Magento module project:

# 1. Module skeleton - Copilot completes file structure
# Effort saved: 20 minutes

# 2. Repository class - standard CRUD, Copilot fills in the pattern
# Effort saved: 10 minutes

# 3. Tests - paste the service class, ask Claude for tests
# Effort saved: 30 minutes (especially data providers)

# 4. Hard problem debugging - paste error + context to Claude
# Explains what went wrong faster than reading docs
# Effort saved: 15-60 minutes depending on the problem

# 5. Code review - paste a diff to Claude before pushing PR
# "Review this for Magento 2 antipatterns and missing null checks"
# Catches things I missed under deadline pressure
# Effort saved: review issues in production

# Total: 1-2 hours saved per feature, on a typical module

The test that shows AI’s limits

<?php

// Ask Claude or Copilot:
// "Write a Magento 2 plugin that modifies the checkout totals
//  for B2B customers with credit limit check and minimum order enforcement"

// You will get code that:
// - Uses the right pattern (plugin on collectTotals)
// - Has reasonable-looking logic
// - Fails because it doesn't handle multi-address checkout
// - Fails because the credit limit check is synchronous but needs async refresh
// - Misses the interaction with MSI salable quantity check

// The AI does not know your business rules, your data model,
// or the specific version quirks of your Magento installation.
// It generates plausible code - you must be the expert who reviews it.

Summary

AI coding tools are a genuine productivity multiplier for repetitive tasks, test writing, boilerplate, and debugging known patterns. They are unreliable for version-specific Magento code, third-party integrations, complex business logic, and security-sensitive code. The correct mental model: AI is a smart autocomplete that needs a senior developer to review every suggestion. It does not replace expertise – it accelerates someone who already has it.

About Henryk Tews

What you can read next

PHP 7.2 – object type hint, sodium instead of mcrypt, deprecations

© 2026 Created by

TOP
Zarządzaj zgodą
Aby zapewnić jak najlepsze wrażenia, korzystamy z technologii, takich jak pliki cookie, do przechowywania i/lub uzyskiwania dostępu do informacji o urządzeniu. Zgoda na te technologie pozwoli nam przetwarzać dane, takie jak zachowanie podczas przeglądania lub unikalne identyfikatory na tej stronie. Brak wyrażenia zgody lub wycofanie zgody może niekorzystnie wpłynąć na niektóre cechy i funkcje.
Funkcjonalne Always active
Przechowywanie lub dostęp do danych technicznych jest ściśle konieczny do uzasadnionego celu umożliwienia korzystania z konkretnej usługi wyraźnie żądanej przez subskrybenta lub użytkownika, lub wyłącznie w celu przeprowadzenia transmisji komunikatu przez sieć łączności elektronicznej.
Preferencje
Przechowywanie lub dostęp techniczny jest niezbędny do uzasadnionego celu przechowywania preferencji, o które nie prosi subskrybent lub użytkownik.
Statystyka
Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do celów statystycznych. Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do anonimowych celów statystycznych. Bez wezwania do sądu, dobrowolnego podporządkowania się dostawcy usług internetowych lub dodatkowych zapisów od strony trzeciej, informacje przechowywane lub pobierane wyłącznie w tym celu zwykle nie mogą być wykorzystywane do identyfikacji użytkownika.
Marketing
Przechowywanie lub dostęp techniczny jest wymagany do tworzenia profili użytkowników w celu wysyłania reklam lub śledzenia użytkownika na stronie internetowej lub na kilku stronach internetowych w podobnych celach marketingowych.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Zobacz preferencje
  • {title}
  • {title}
  • {title}