Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP 7


cornishpirate

Recommended Posts

  • Replies 93
  • Created
  • Last Reply

I had not seen that error before, but a little Googling and reading showed that it's popping up for others with other software.  Normally, PHP errors can be found with Google and see how others solve it.  My thought was that it was a string that needed to be cast, but i wasn't certain.  Most of the OSC code cast variables years ago, but addons don't have it.  Anyway, we both learned today and that's always a good thing. 

I'm not really a dog.

Link to comment
Share on other sites

Try this.  Did a little searching on StackOverflow and learned a little more.  Had to add the Hash class so I could experiment.  This yeilds an output now.

  function tep_random_name()
  {
    $letters = 'abcdefghijklmnopqrstuvwxyz';
    $dirname = '.';
    $length = floor(Hash::getRandomInt(16, 20));
    for ($i = 1; $i <= $length; $i++) {
      $q = floor(Hash::getRandomInt(1, 26));
      $dirname .= $letters[(int)$q];
    }
    return $dirname;
  }

 

I'm not really a dog.

Link to comment
Share on other sites

It only works when there's no z in the output.  I ran into this on another piece of Harald's code I was playing with.  I found a workaround, but it's not a good one and I'm not sure why it even works.  Putting a -1 after $q stops errors.

  function tep_random_name()
  {
    $letters = 'abcdefghijklmnopqrstuvwxyz';
    $dirname = '.';
    $length = floor(Hash::getRandomInt(16, 20));
    for ($i = 1; $i <= $length; $i++) {
      $q = floor(Hash::getRandomInt(1, 26));
      $dirname .= $letters[(int)$q-1];
    }
    return $dirname;
  }

 

I'm not really a dog.

Link to comment
Share on other sites

I was just talking about the hash functions used, but I don't really have an argument for it.  http://www.php.net/Hash

I just put the function into a test page and the errors went away after the (int) addition, but I was just testing the output of the function.  I did get the string offset errors at first.

I'm not really a dog.

Link to comment
Share on other sites

There are various functions around (e.g., tempnam, or possibly tmpfile) for creating unique temporary file names. It might be cleaner to use one of them. Also, when generating names, you have two problems:

  1. I don't see anything to prevent duplicates (unlikely, but still possible).
  2. Depending on who can see these names, some might be offensive. An easy way out of this to to drop the vowels and use only the 20 consonants.
Link to comment
Share on other sites

  • 3 months later...
1 hour ago, Daniel204 said:

what about the PHP 7?

tried it, liked it

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

(At the risk of reviving an old thread, with a (perhaps) off-topic question ... )

Is there a problem with coding a shop to run under PHP 7.2, and actually running in under PHP 5.6?

The reason I ask is that I have several shop on my host's server. As I update each shop, I want to bring each up to be PHP 7.2 ready (even though my host currently only offers up to PHP 7.0), but leave all the shops at PHP 5.6 until all are upgraded. Will and PHP 7.2 specific code cause a problem under PHP 5.6?

TIA

M

Link to comment
Share on other sites

@ArtcoInc generally speaking, it shouldn't be a problem. There is syntax on 7-7.2 that isn't supported on 5.6 but you're probably not going to be using any of it in your new version... spaceships <=>, null coalescing ($action = $_GET['action'] ?? 'default'), anonymous classes, constant arrays and a bunch of other things that don't spring straight to mind.

The only bit of code I can think of that doesn't work across versions is something to do with error-handling on evals but you probably haven't got any of that anyway. The evaluation order in statements is the other way round (eg. when working out what $$class->$method($param[$$key]) means but that should have been fixed by putting in curly braces to make it expllicit in the statement.

The approach would be - get a set of code running without issue on 7 and then turn the version back down to 5.6 for a test.

hth

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 7 months later...
  • 3 weeks later...

@BrockleyJohn @ArtcoInc @raiwa

Hi,

Anyone know how to solve the "undefined method objectInfo" error encountered in admin/catagories.php ? :

Fatal error: Uncaught Error: Call to undefined method objectInfo::objectInfo() in D:\wamp\www\admin\categories.php on line 775
Error: Call to undefined method objectInfo::objectInfo() in D:\wamp\www\admin\categories.php on line 775

Here is the class objectInfo :
 

  class objectInfo {

// class constructor
    function __construct($object_array) {
//      reset($object_array);
//      while (list($key, $value) = each($object_array)) {
	  foreach ($object_array as $key => $value) {
        $this->$key = tep_db_prepare_input($value);
      }
    }
  }
?>


Ok, I have found this fix https://github.com/gburton/CE-Phoenix/blob/master/admin/includes/classes/object_info.php?fbclid=IwAR0vd1Gx3ArEYkCm7SViCTKqHVlbl21vXmTbookJwjSjNMwf_nJxJ0Zl88s
 

<?php
/*
  $Id$
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2003 osCommerce
  Released under the GNU General Public License
*/
  class objectInfo {
// class constructor
    function __construct($object_array) {
		  $this->objectInfo($object_array);
		}
    function objectInfo($object_array) {
      foreach($object_array as $key => $value) {
        $this->$key = tep_db_prepare_input($value);
      }
    }
  }
?>

 

Osc v2.3.4 BS "custom"
PHP 7.3 compatible (710 modified files => o_O')

Link to comment
Share on other sites

@milerwan yes, use the version of the class from phoenix, frozen etc which has the proper fix for php7.

In this case you don't rename the constructor you add one and call the existing eponymous method because it's called directly.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

specificially:

function __construct($object_array) {
  $this->objectInfo($object_array);
}

 

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

24 minutes ago, BrockleyJohn said:

@milerwan yes, use the version of the class from phoenix, frozen etc which has the proper fix for php7.

In this case you don't rename the constructor you add one and call the existing eponymous method because it's called directly.

@BrockleyJohn

Yes, thank you !

I have another issue from "checkout_shipping" page with strange errors.
Could you take a look on it, it is reported here :

NB: I have just tried to used Phoenix's "checkout_shipping.php" script too but same errors...

Thank for your help.

Osc v2.3.4 BS "custom"
PHP 7.3 compatible (710 modified files => o_O')

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...