Skip to content

Fix PHP 8.1/8.4 deprecations: strftime() and implicit nullable types#4

Open
AlexanderSinani wants to merge 2 commits into
DavidGoodwin:masterfrom
AlexanderSinani:fix/php81-strftime-deprecation
Open

Fix PHP 8.1/8.4 deprecations: strftime() and implicit nullable types#4
AlexanderSinani wants to merge 2 commits into
DavidGoodwin:masterfrom
AlexanderSinani:fix/php81-strftime-deprecation

Conversation

@AlexanderSinani

Copy link
Copy Markdown

Summary

Two categories of PHP 8.x deprecation notices fixed:

1. strftime() deprecated since PHP 8.1 (18 files)

strftime() was deprecated in PHP 8.1 and will be removed in PHP 9. Every builder that writes an "autogenerated on" comment called strftime('%c'). Fixed with date('D M j G:i:s Y') (locale-independent, equivalent output).

The more impactful fix is in PHP5ObjectBuilder: the template emitted into every generated Base*.php temporal accessor called strftime($format, ...) for %-prefixed format strings. This has been replaced with a strtr()-based mapping to date() equivalents, covering the common specifiers (%Y %y %m %d %H %M %S %s %A %a %B %b %W %u %e %I %p %P %Z %z). Plain date() format strings (no %) continue to work unchanged.

2. Implicit nullable types deprecated in PHP 8.4 (12 files)

PHP 8.4 deprecates parameters that have a type hint and a default value of null but are not declared ?Type. This generates a deprecation notice on every call.

  • Generator templates (PHP5ObjectBuilder, PHP5ObjectNoCollectionBuilder, PHP5NestedSetBuilder, PHP5NestedSetPeerBuilder, PHP5NodeBuilder, PHP5NodePeerBuilder, QueryBuilder): template strings emitting PropelPDO $con = null and Criteria $criteria = null now emit ?PropelPDO $con = null etc.
  • Runtime (PropelException, NodeObject, NodePeer, ModelCriteria, PropelDateTime): actual PHP signatures for PropelPDO, NodeObject, Exception, and DateTimeZone parameters updated to use explicit ?Type.

strftime() was deprecated in PHP 8.1 and removed in PHP 9.0.

Two categories of fixes:

1. Generator timestamp comments (18 files): replace
      $now = strftime('%c')
   with
      $now = date('D M j G:i:s Y')
   This affects every OM builder that writes an "autogenerated on" comment
   into the generated file header.

2. Generated date getter code (PHP5ObjectBuilder only): the template
   that is written into every Base*.php temporal accessor previously
   emitted a call to strftime() for %-prefixed format strings. This is
   replaced with a strtr()-based mapping to date() equivalents, covering
   the most common strftime specifiers (%Y %m %d %H %M %S %s %A %a
   %B %b %W %u %e %I %p %P %Z %z).  Plain date() format strings (no %)
   continue to work unchanged.
PHP 8.4 deprecates implicitly nullable typed parameters — where a
parameter has a type hint and a default of null but is not declared
?Type. This generates a deprecation notice on every call site and
will become a hard error in a future version.

Two areas affected:

1. Generator templates (generator/lib/builder/om/): the strings
   emitted into generated OM files used \$con = null without ?.
   Fixed in PHP5ObjectBuilder, PHP5ObjectNoCollectionBuilder,
   PHP5NestedSetBuilder, PHP5NestedSetPeerBuilder, PHP5NodeBuilder,
   PHP5NodePeerBuilder, QueryBuilder.

2. Runtime library (runtime/lib/): actual PHP code in PropelException,
   NodeObject, NodePeer, ModelCriteria, PropelDateTime used implicit
   nullable for PropelPDO, NodeObject, Exception, and DateTimeZone
   parameters.

All affected signatures now use the explicit ?Type notation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant