PHP 8.2 - Community Input

Open to all! Ask other shopowners for help.
User avatar
bonbec
Contributor
Posts: 190
Joined: Mon Oct 26, 2020 12:23 pm
Phoenix Version: V1.1.0.7
Has thanked: 54 times
Been thanked: 40 times

Re: PHP 8.2 - Community Input

Post by bonbec »

For strftime, I tried to do something, but it's not finished because I'm not a coder.
What will take 5 minutes to @burt or @ecartz (to name a few), it takes me an hour... so please bear with my modest code.
I tested it only on the index page.

In the include/functions/html_output.php file:

Code: Select all

function formatted_date($format, $date){

	if(empty($date)){
		$date = date("Y-m-d H:i:s");
	} else {
		$date = date("Y-m-d H:i:s", $date);		
	}
	$actualdatetime = new DateTime($date);
	
	switch ($format) {
    case 'monthletter':
        $theformat = 'MMMM';
        break;
    case 'short':
		// '%d/%m/%Y' this is used for strftime() 
		// d = jour 0 à 31
		// m = mois sur 2 chiffres 01 à 12
		// Y =  année sur 4 chiffres
        $theformat = 'dd/M/YYYY'; 
        break;
	case '%d/%m/%Y':
		// '%d/%m/%Y' this is used for strftime() 
		// d = jour 0 à 31
		// m = mois sur 2 chiffres 01 à 12
		// Y =  année sur 4 chiffres
        $theformat = 'dd/M/YYYY'; 
        break;
    case 'long':
		// '%A %d %B %Y' this is used for strftime()
		// A = nom du jour en lettres
		// d = jour 0 à 31
		// B = mois en lettres suivant LOCALE
		// Y =  année sur 4 chiffres
        $theformat = 'EEEE dd M YYYY'; 
        break;
    default:
       echo "not finish ...";
	   $theformat = 'EEEE dd M YYYY'; 
	}

    $fmt = datefmt_create(
        LANGUAGE_LOCALE,
        IntlDateFormatter::FULL,
        IntlDateFormatter::FULL,
        LANGUAGE_TIMEZONE,
        IntlDateFormatter::GREGORIAN,
        $theformat
    );

    $formatted_result = datefmt_format($fmt, $actualdatetime);

    return $formatted_result;
}
In the language file, french.php for me:

Code: Select all

const LANGUAGE_LOCALE = 'fr_FR';
const LANGUAGE_TIMEZONE = 'Europe/Paris';
I modified line 2 of include/modules/content/index/templates/tpl_cm_i_card_products.php
Remplace

Code: Select all

printf(MODULE_CONTENT_CARD_PRODUCTS_HEADING, strftime('%B')); 
by

Code: Select all

printf(MODULE_CONTENT_CARD_PRODUCTS_HEADING, formatted_date('monthletter', ''));
I modified line 45 of file include/system/versionned/1.0.8.3/date.php
Remplace

Code: Select all

? strftime($format, $this->timestamp)
by

Code: Select all

? formatted_date($format, $this->timestamp)
There you go, I didn't go any further. If this could be a clue...

The result in the index page :
strftime.jpg
You do not have the required permissions to view the files attached to this post.
Old MS2.2 PHP7.4 site being converted to CE Phoenix v1.1.0.6 PHP 8.3


Join The Code Co-op to get access to your library in the Code Co-op Forum
Omar_one
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: PHP 8.2 - Community Input

Post by Omar_one »

any help, thank you in advace

Code: Select all

PHP Deprecated:  Creation of dynamic property i_adverts::$advert_width is deprecated in /home/shop/public_html/includes/modules/pi/index/i_adverts.php on line 32
PHP Deprecated:  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /home/shop/public_html/includes/modules/header_tags/ht_twitter_product_card.php on line 36
PHP Deprecated:  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /home/shop/public_html/includes/modules/content/header/cm_header_breadcrumb.php on line 87
PHP Deprecated:  Creation of dynamic property paypal_standard::$signature is deprecated in /home/shop/public_html/includes/modules/payment/paypal_standard.php on line 39
PHP Deprecated:  Creation of dynamic property paypal_standard::$api_version is deprecated in /home/shop/public_html/includes/modules/payment/paypal_standard.php on line 40
PHP Deprecated:  Creation of dynamic property paypal_standard::$public_title is deprecated in /home/shop/public_html/includes/modules/payment/paypal_standard.php on line 43
PHP Deprecated:  Creation of dynamic property paypal_standard::$sort_order is deprecated in /home/shop/public_html/includes/modules/payment/paypal_standard.php on line 47
PHP Deprecated:  Creation of dynamic property paypal_standard::$order_status is deprecated in /home/shop/public_html/includes/modules/payment/paypal_standard.php on line 49
PHP Deprecated:  Creation of dynamic property paypal_standard::$form_action_url is deprecated in /home/shop/public_html/includes/modules/payment/paypal_standard.php on line 58
PHP Deprecated:  substr(): Passing null to parameter #1 ($string) of type string is deprecated in /home/shop/public_html/includes/apps/paypal/OSCOM_PayPal.php on line 182
PHP Deprecated:  Creation of dynamic property wishlist::$listID is deprecated in /home/shop/public_html/includes/system/versioned/1.0.7.other/1.0.7.12/wishlist.php on line 65
PHP Deprecated:  Creation of dynamic property wishlist::$listID is deprecated in /home/shop/public_html/includes/system/versioned/1.0.8.3/session.php on line 55
PHP Deprecated:  mysqli::real_escape_string(): Passing null to parameter #1 ($string) of type string is deprecated in /home/shop/public_html/includes/system/override/versioned/1.0.8.1/database_core.php on line 93
PHP Deprecated:  Function strftime() is deprecated in /home/shop/public_html/includes/modules/notifications/templates/tpl_n_checkout.php on line 19
PHP Deprecated:  Creation of dynamic property mime::$lf is deprecated in /home/shop/public_html/includes/system/versioned/1.0.4.5/mime.php on line 48
PHP Deprecated:  Creation of dynamic property mime::$lf is deprecated in /home/shop/public_html/includes/system/versioned/1.0.4.5/mime.php on line 48
PHP Deprecated:  Creation of dynamic property mime::$lf is deprecated in /home/shop/public_html/includes/system/versioned/1.0.4.5/mime.php on line 48
PHP Warning:  Undefined array key "currency" in /home/shop/public_html/includes/system/versioned/1.0.7.10/cart_order_builder.php on line 42
PHP Warning:  Undefined array key "currency" in /home/shop/public_html/includes/system/versioned/1.0.7.10/cart_order_builder.php on line 43
PHP Warning:  Undefined array key "" in /home/shop/public_html/includes/system/versioned/1.0.7.10/cart_order_builder.php on line 43
PHP Warning:  Trying to access array offset on value of type null in /home/shop/public_html/includes/system/versioned/1.0.7.10/cart_order_builder.php on line 43
PHP Fatal error:  Uncaught Error: Call to a member function fetch_to_address() on null in /home/shop/public_html/includes/system/versioned/1.0.7.10/cart_order_builder.php:65
Stack trace:
#0 /home/shop/public_html/includes/system/versioned/1.0.7.10/cart_order_builder.php(149): cart_order_builder->build_addresses()
#1 /home/shop/public_html/includes/system/versioned/1.0.7.10/order.php(25): cart_order_builder::build(Object(order))
#2 /home/shop/public_html/includes/classes/magic/loader.php(16): order->__construct()
#3 /home/shop/public_html/includes/system/versioned/1.0.8.1/hooks.php(164): Loader->__call('order', Array)
#4 /home/shop/public_html/includes/system/segments/checkout/pipeline.php(14): hooks->generate('startCheckout')
#5 /home/shop/public_html/ahcocheckoutpsp.php(108) : eval()'d code(3): require('/home/shop/p...')
#6 /home/shop/public_html/ahcocheckoutpsp.php(108): eval()
#7 {main}
  thrown in /home/shop/public_html/includes/system/versioned/1.0.7.10/cart_order_builder.php on line 65
cut-n-paste
Member
Posts: 28
Joined: Fri Oct 07, 2022 12:20 pm
Phoenix Version:
Has thanked: 2 times
Been thanked: 5 times

Re: PHP 8.2 - Community Input

Post by cut-n-paste »

@ecartz @burt
This seems to be a quick fix for strftime()

Make the following changes to /includes/system/versioned/1.0.8.3/date.php

Replace function format() with this: EDIT: Added internationalisation with IntlDateFormatter()

Code: Select all

public function format($format) {
    if ($this->timestamp) {
        $dateFormat = Date::strftimeToDateFormat($format);
        $locale = locale_get_default();
        $formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::MEDIUM);
        $timestamp = $this->timestamp;

        return $formatter->format($timestamp);
    } else {
        return false;
    }
}
Add this new function:

Code: Select all

public static function strftimeToDateFormat($strftimeFormat) {
  $conversion = array(
    '%a' => 'D',     // Abbreviated weekday name
    '%A' => 'l',     // Full weekday name
    '%b' => 'M',     // Abbreviated month name
    '%B' => 'F',     // Full month name
    '%c' => 'r',     // Date and time representation
    '%C' => 'y',     // Century (00-99)
    '%d' => 'd',     // Day of the month (01-31)
    '%D' => 'm/d/y', // Short date (mm/dd/yy)
    '%e' => 'j',     // Day of the month (1-31)
    '%F' => 'Y-m-d', // ISO 8601 date (YYYY-MM-DD)
    '%g' => 'y',     // Last 2 digits of the week-based year (00-99)
    '%G' => 'Y',     // Week-based year
    '%h' => 'M',     // Abbreviated month name (same as %b)
    '%H' => 'H',     // Hour in 24-hour format (00-23)
    '%I' => 'h',     // Hour in 12-hour format (01-12)
    '%j' => 'z',     // Day of the year (001-366)
    '%m' => 'm',     // Month (01-12)
    '%M' => 'i',     // Minute (00-59)
    '%p' => 'A',     // AM or PM
    '%r' => 'h:i:s A', // 12-hour time (hh:mm:ss AM/PM)
    '%R' => 'H:i',    // 24-hour time (hh:mm)
    '%S' => 's',      // Second (00-59)
    '%T' => 'H:i:s',  // 24-hour time with seconds (hh:mm:ss)
    '%u' => 'N',      // Day of the week (1-7, 1=Monday, 7=Sunday)
    '%U' => 'W',      // Week number of the year (00-53, Sunday as the first day of the week)
    '%V' => 'W',      // ISO week number of the year (01-53)
    '%w' => 'w',      // Day of the week (0-6, 0=Sunday, 6=Saturday)
    '%x' => 'Y-m-d',  // Locale's date representation
    '%X' => 'H:i:s',  // Locale's time representation
    '%y' => 'y',      // Last 2 digits of the year (00-99)
    '%Y' => 'Y',      // Year with century (e.g., 2023)
    '%z' => 'O',      // Timezone offset (+HHMM or -HHMM)
    '%Z' => 'T',      // Timezone name
    '%%' => '%',      // A literal '%'
  );

  $dateFormat = strtr($strftimeFormat, $conversion);

  return $dateFormat;
}
Then replace any reference to strftime() with date(Date::strftimeToDateFormat()) eg

Code: Select all

strftime(STORE_PARSE_DATE_TIME_FORMAT)
Becomes

Code: Select all

date(Date::strftimeToDateFormat(STORE_PARSE_DATE_TIME_FORMAT))
These files need strftime() to be replaced:
admin/define_language.php
admin/includes/classes/logger.php
includes/application_bottom.php
includes/modules/content/index/templates/tpl_cm_i_card_products.php
includes/modules/content/index_nested/templates/tpl_cm_in_card_products.php
includes/modules/notifications/templates/tpl_n_checkout.php
Last edited by cut-n-paste on Mon Nov 13, 2023 1:44 pm, edited 1 time in total.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: PHP 8.2 - Community Input

Post by ecartz »

The date function is not internationalized and is not a replacement for strftime. This may work for you, but it is not a fix for the basic problem.

It's easy enough to change the formats. The problem is providing a polyfill for the internationalized version when it is not available. Since PHP in its infinite wisdom decided to deprecate strftime without including a replacement in core.
User avatar
bonbec
Contributor
Posts: 190
Joined: Mon Oct 26, 2020 12:23 pm
Phoenix Version: V1.1.0.7
Has thanked: 54 times
Been thanked: 40 times

Re: PHP 8.2 - Community Input

Post by bonbec »

The test I did works for all languages if we add two constants in the language files (for example french.php for my case):

Code: Select all

const LANGUAGE_LOCALE = 'fr_FR';
const LANGUAGE_TIMEZONE = 'Europe/Paris';
which we then use like this:

Code: Select all

$fmt = datefmt_create(
         LOCAL_LANGUAGE,
         IntlDateFormatter::FULL,
         IntlDateFormatter::FULL,
         LANGUAGE_TIMEZONE,
         IntlDateFormatter::GREGORIAN,
         $theformat
     );
On the other hand, my code needs to be optimized and completed...
Old MS2.2 PHP7.4 site being converted to CE Phoenix v1.1.0.6 PHP 8.3
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: PHP 8.2 - Community Input

Post by ecartz »

IntlDateFormatter is not available in all PHP installations. If it works for you, great. But it isn't a general solution. The general solution needs a polyfill for IntlDateFormatter when it is not available.

Making this work on

1. Versions where IntlDateFormatter is available.
2. Versions where it is not but strftime still works.
3. Versions where neither work.

Is what is hard. It is particularly difficult because strftime sometimes works but generates deprecated messages. If you can pick one of those three situations, then it becomes easy. In the third, you lose internationalization. The great advantage of strftime was that it was available everywhere, as it was in core. Now we do not have the promise of internationalization being in core. We particularly do not have anything that works for internationalization in both 7.4 and 8.2. Because strftime no longer works in 8.2 and IntlDateFormatter was often omitted in 7.4.

We're likely to drop strftime after 1.0.9.0, but I don't want to do it before then. Because people are still using 7.4 and should have a .0 version.
cut-n-paste
Member
Posts: 28
Joined: Fri Oct 07, 2022 12:20 pm
Phoenix Version:
Has thanked: 2 times
Been thanked: 5 times

Re: PHP 8.2 - Community Input

Post by cut-n-paste »

Seems to me like IntlDateFormatter is mostly available or easy to enable as it's been built in since 5.3.0, according to the PHP documentation.

Phoenix Cart already has the MySQLi extension as a prerequisite.

@ecartz what am I missing here?
Omar_one
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: PHP 8.2 - Community Input

Post by Omar_one »

how to fix the order confirmation mail as the order info not shown on the email
Br
Omar

EDIT : working fine now .. without doing anything magic :D
Last edited by Omar_one on Sat Nov 25, 2023 6:58 pm, edited 1 time in total.
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: PHP 8.2 - Community Input

Post by burt »

Omar_one wrote: Fri Nov 10, 2023 10:38 am how to fix the order confirmation mail as the order info not shown on the email
Br
Omar
Is this a problem introduced in PHP8.2
or a bug/error in Phoenix (ie also happens in earlier versions PHP)?
I am not here to build for you.
I am here to build with you. Let's help each other.
Omar_one
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: PHP 8.2 - Community Input

Post by Omar_one »

burt wrote: Fri Nov 10, 2023 12:48 pm Is this a problem introduced in PHP8.2
or a bug/error in Phoenix (ie also happens in earlier versions PHP)?
Is this a problem introduced in PHP 8.2 it was working well on PHP 7.4


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply