joechrysler / calendar

1 stars 2 forks source link

Broken with PHP 8.2 in Debian 12 (bookworm?) #1

Open l8gravely opened 10 months ago

l8gravely commented 10 months ago

Hi, I'm working to upgrade an old old site using this code, and it's failing to run on Debian 12 using php 8.2. I get a bunch of errors like:

PHP Warning: Undefined property: activeCalendar::$eventID in /path/to/my/site/activecalendar.php

and I suspect it's because of the changes in how classes are handled in PHP. It's also using the adodb date-time library, since my calendars are all from the 1600-1900 time frame and I needed to use a library which could generate calendars and dates for then. I'm completely clueless when it comes to PHP and classes, hoping others could help give suggestions after looking at the raw code here.

I'll keep poking at it myself, and maybe I'll make some progress.

Some thoughts from all my googling:

  1. declare all the eventid (and other vars in the class) as public vars.
  2. when creating the entry, make sure to initialize all vars (properties?), even if the aren't being used. Maybe it's happening the isEvent() function where it's not setting it for all instances of the class? Still trying to wrap my brain around the code again.

I suspect I'm on my own, but hey, you've got the base code in a repo, maybe you know more than me. :-)

l8gravely commented 10 months ago

and of course I'm really talking about the activecalendar stuff under calendar/Examples/activecalendar/ which is where I'm having problems making this work properly.

l8gravely commented 10 months ago

Ok, so I've got it at least running without throwing any errors, just by adding various variables to the top of the class definition. I'll post a diff in a bit. But I'm still not able to get it to work with the adodb-time library, since I need to create calendars from before 1900, which breaks the regular PHP libraries. Fun fun... I'll keep pounding on this and trying to figure out the problem. Hopefully it's not a library issue, since I do find the adodb_mkgmtime() calls when running my test script to generate a library in 1850. My test code is just:

<?php
# Debugging aid                                                                                     
error_reporting (E_ALL);

require_once "adodb/adodb-time.inc.php";
require_once "activecalendar.php";

# January 1850...                                                                                   
$cal = new activeCalendar(1850,1);
$cal->setFirstWeekDay(0);
print $cal->showYear(3, 0);
?>

But when I run it with 'php -f make-1850.php' I still get a calendar from december 2023. This works fine under older versions of php from Debian 11.

l8gravely commented 10 months ago

And I've found out that using constructors named after the package itself are now not welcome. So once I added in a function __construct(....) { }

Things seem to be working again. Still some issues to fix before I post a complete patch. This has been fun to dig into...

steve386 commented 9 months ago

@l8gravely I'm running into the same issue trying to coax activeCalendar to work on PHP 8.0. Have you gotten any further in your journey?

l8gravely commented 9 months ago

"Steve" == Steve Johnson @.***> writes:

@l8gravely I'm running into the same issue trying to coax activeCalendar to work on PHP 8.0. Have you gotten any further in your journey?

I have! I've got it working with my code. I've attached my working patch for you to test out. Some of it's just me re-writing code to make it less dense and easier to read. But the basic idea is to update how the class is defined and it add in some initializers for various stuff. I'd love to get some feedback on how well this works for you.

John

steve386 commented 9 months ago

Hi John It doesn't look like the attachment made it through (or I'm just not seeing it). However, using some of your earlier thoughts in this thread, I believe that I have it working! I made three significant changes.

  1. Declare some miscellaneous public methods:

    public $timetoday;
    public $selectedday;
    public $selectedyear;
    public $selectedmonth;
    public $unixtime;
    public $daytoday;
    public $monthtoday;
    public $yeartoday;
    public $actday;
    public $actmonth;
    public $actyear;
    public $has31days;
    public $isSchalt;
    public $maxdays;
    public $firstday;
    public $GMTDiff;
    public $weekNumTitle;
    public $weekUrl;
    public $showNoMonthDays;
    public $eventID;
  2. Rename the function activeCalendar to __construct.

  3. I commented out all references to adodb_* functions, and had them return the PHP calculation instead.

With that, it seems to be working fine, and not throwing any errors. I am curious if you made any other changes, or feel like I've missed anything. Thanks for your time!

-Steve

l8gravely commented 9 months ago

"Steve" == Steve Johnson @.***> writes:

It doesn't look like the attachment made it through (or I'm just not seeing it). However, using some of your earlier thoughts in this thread, I believe that I have it working! I made three significant changes.

Yeah, the attachment didn't make it through. Been looking into getting my git-fu in shape again to create a proper patch and to push it up as a proposed patch.

But turns out I have some other custom code in the library from my current app that I needed to cleanup as well. And I had alos made a bunch of whitespace and formatting changes which really didn't need to be in there. I personally want to re-format that code base to be easier to read (for my eyes!) but that's a seperate step of course.

  1. Declare some miscellaneous public methods: public $timetoday; public $selectedday; public $selectedyear; public $selectedmonth; public $unixtime; public $daytoday; public $monthtoday; public $yeartoday; public $actday; public $actmonth; public $actyear; public $has31days; public $isSchalt; public $maxdays; public $firstday; public $GMTDiff; public $weekNumTitle; public $weekUrl; public $showNoMonthDays; public $eventID;

I mostly made a bunch of extra variable initializers to shut up the errors.

  1. Rename the function activeCalendar to __construct.

I actually added the __contruct() call and had it call the activeCalendar() function so that apps using it didn't need to be changed at all. Needs better testing.

  1. I commented out all references to adodb_* functions, and had them return the PHP calculation instead.

I did this too, especially since that library is now deprecated. That should be a seperate patch with some PHP version checks for older versions of PHP.

With that, it seems to be working fine, and not throwing any errors. I am curious if you made any other changes, or feel like I've missed anything. Thanks for your time!

I think you've really hit the nail on the head. So sorry for not getting my patch sent in properly. Re-learning my github-fu after not using it for a while.

It might be time to actually setup a true "activecalendar" repo with just this library with the patches for PHP 8+ and removal of adodb_time library. The current joechrylser/calendar github repo is really a super-set of the base library.

I also tried finding the original author online, but no luck. So it's probably safe to just take it over and publicize it so others can find this work.

A bit thank you to Joe Chrysler for his repo, made my life easier in some ways!

John

steve386 commented 9 months ago

I maintain an internal app, and my company is moving from Oracle Linux to Red Hat Enterprise Linux, and PHP is jumping from 7.2 to 8.0. I was already rewriting the app from the ground up, but now I need the old version to limp to the finish line lol. That's what got me started down this rabbit hole, but I think I'm there with the mods I mentioned before. With the new version, I decided on FullCalendar https://fullcalendar.io for calendaring. It's very robust if you want to check it out. Thanks ever so much for posting this thread, I don't think I would have gotten here without it!

-Steve