Aspose for PHP via Java - PHP 8.1 support?

Hello, my application has purchased an OEM site license for Aspose.Total for PHP via Java.

Following the setup instructions here: Aspose.Total for PHP via Java|Documentation

The Aspose site says:

Aspose.Total for PHP via Java is platform independent API and can be used on any platform (Windows, Linux, MacOS etc.) where PHP 7 or greater versions is installed

I am running PHP 8.1, which meets this criteria. When I install the JavaBridge from the indicated location, it does not run with PHP 8.1 because the java.inc file (which is PHP code) does not correctly declare return types for several Java implementations of PHP functions.

I realize this is a third party library, but it seems that Aspose has said this would work with PHP 8.1 - so I am wondering, does Aspose have an updated version of the java.inc file that will allow the javabridge to function on PHP 8 and allow us to run Aspose.Total on PHP? Thank you.

@backprop

Can you please confirm which specific API from Aspose.Total package are you using? We will further proceed to assist you accordingly.

Hello, I used Aspose.Words, Aspose.Sheets, Aspose.PDF, and Aspose.Slides. However, I believe that the use of the javabridge is exactly the same across all packages. Thank you.

@backprop,
Could you please share descriptions of the errors you are experiencing for each Aspose product you used? Also indicate the instruction and step at which the error occurs. It will be great if you share a scenario leading to the errors.

Hi Andrey - sure.

As I mentioned above, I realize the error isn’t technically with Aspose. But I don’t believe Aspose will work with PHP 8.x+ unless JavaBridge works with PHP v8.x+. This issue prevents that.

According to the Aspose for PHP via Java installation guide, we first have to install JavaBridge in order to communicate with any Aspose for Java product from PHP code. If you install JavaBridge with PHP 8.1, the first call to initialize javabridge includes the java.inc file that comes packaged with JavaBridge:

require_once ("http://localhost:8080/JavaBridge/java/Java.inc");

However, that file, which is PHP code that gets executed, is not designed to work with PHP 8, and the javabridge project is not actively managed to provide an updated version.

The java.inc file extends some PHP built-in classes and implements some PHP built-in interfaces, but does not correctly declare the base return types of those classes and interfaces. This became a requirement in PHP 8. So, as soon as you include and execute the java.inc file as shown above, an error is apparent:

Fatal error: During inheritance of Iterator: Uncaught ErrorException: Return type of java_objectIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice.

There are a number of methods in that file that need to be updated in order for JavaBridge to work with PHP8+.

Again, I acknowledge that this is not an Aspose project per se, but if Aspose does want to remain compatible with PHP “7 or greater” as per the instructions, it might be nice if Aspose could provide a source java.inc file that will work with the newer versions of PHP. Otherwise each customer has to modify individual pieces of the source java.inc file which is out of scope of the instructions provided.

Thanks for your consideration.

@backprop,
Thank you for the details. We will get back to you ASAP.

@backprop
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESPHP-68

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@backprop
Regarding Aspose.Cells for PHP via Java, we need to investigate your issue in details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSPHPJAVA-48

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@backprop,
I added #[\ReturnTypeWillChange] to relevant lines in Java.inc file. The Deprecated Warnings Disappeared.
Some sample codes as follows:

#[\ReturnTypeWillChange]
function rewind() {
reset($this->var);
}
#[\ReturnTypeWillChange]
function valid() {
return $this->current() !==false;
}
#[\ReturnTypeWillChange]
function next() {
return next($this->var);
}
function getWebApp() {
$context=$this->getWebAppInternal();
if(is_null($context)) $context=JAVA_SERVLET;
if(is_null($context) || ((string)$context)[0]!="/")
$context="/JavaBridge/JavaBridge.phpjavabridge";
return $context;
}

Can you try it?

Hi John, thank you; yes, indeed manually modifying the file does work.

However, that tag is a temporary patch with PHP 8.1 and will not work with PHP 9; thus PHP warns that it should have a more permanent fix. But it does work for the time being.

More importantly, I wanted to emphasize that it might be a good idea for Aspose to officially indicate in its installation documentation for “Aspose.Total for PHP via Java” how users should modify the file, or to provide a modified file for those who purchase Aspose with the intention that it works “out of the box” with PHP and javabridge. Having it at least in the instructions would assure Aspose users that Aspose will continue to support PHP 8+ even if the javabridge project itself is not actively maintained. Thank you.

@backprop,

It is nice to know that it figures out your issue now.

We will evaluate it further and get back to you soon.

Yes, we can provide details in the docs. We can guide users on how to modify the relevant file for the purpose, but we cannot directly provide updated file to the users due to copyright issues.

@backprop,
Please try to use the following Java.inc file (replace the original java.inc from php-java bridge).
Java.inc.php8.zip (15.0 KB)

The issues you found earlier (filed as SLIDESPHP-68) have been fixed in Aspose.Slides for PHP via Java 23.3 (ZIP).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.

Hi

How can i download your Java.inc ?
I’m in the same situation with php 8.1

Best

@doughidoug,
You can download the file from this post.

@doughidoug,

Since you are not the owner of this thread, so you might not download attachments (attached) in this thread. You may create a new thread in respective category and ask for the attachment. Generally, we can only provide details and guide users on how to modify the relevant file for the purpose but we might not provide updated file to the users due to copyright issues. You may refer to details provided in this thread for reference.