Skip to main content

Posts

Showing posts with the label PHP

Strangler Fig Pattern: Sharing Auth Sessions Between Legacy PHP and Next.js

  The Strangler Fig pattern is the de facto standard for migrating legacy monoliths, but it hits a concrete wall immediately: Authentication. You have a legacy PHP application (Laravel, Symfony, or vanilla) serving the root domain. You deploy a Next.js App Router instance to handle specific routes (e.g.,  /dashboard/analytics ). You configure your load balancer (Nginx/AWS ALB) to route traffic correctly. The browser sends the  PHPSESSID  (or  laravel_session ) cookie to the Next.js server. However, your Next.js application treats the user as unauthenticated. The Root Cause: Serialization Incompatibility The issue is not network reachability or cookie scope. If both apps sit on  example.com , the browser transmits the cookies to both backends. The failure occurs at the  deserialization layer . Storage Format:  PHP sessions are typically stored on the file system ( /var/lib/php/sessions ) or Redis. PHP uses a proprietary serialization format (e.g.,...

Fixing "Deprecated: Creation of dynamic property" in Legacy PHP 8.2 Apps

  If you maintain a legacy PHP codebase or a WordPress plugin that hasn't seen a major refactor since PHP 7.4, your error logs are likely flooding with this message after upgrading to PHP 8.2: Deprecated: Creation of dynamic property ClassName::$propertyName is deprecated This is not a false alarm. While it is currently a deprecation warning, PHP 9.0 will escalate this to a fatal  ErrorException . The era of treating PHP objects as "fancy arrays" where you can attach arbitrary data at runtime is over. The Root Cause: Why PHP Changed Historically, PHP allowed developers to assign values to undeclared properties on any object. Under the hood, the Zend Engine would silently create a dynamic property map (a HashTable) attached to the object instance to store these values. While convenient, this behavior caused two major issues: Performance:  Accessing declared properties is optimized via strict memory offsets. Accessing dynamic properties requires a slower hash table lookup. ...