top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

Seemingly incorrect strict standard in PHP

0 votes
23 views

I've got an abstract class which requires one of the concrete descendants to implement a static function.
The base class will call it using static:: rather than self::. But I'm getting an error at runtime. Static function should not be abstract. It doesn't SEEM right to inhibit this. Am I missing something?
I'm on PHP 5.4.15 (Mac and Centos).

posted Jun 3, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

This change is done on purpose.
From the PHP manual:
"Dropped abstract static class functions. Due to an oversight, PHP 5.0.x and 5.1.x allowed abstract static functions in classes. As of PHP 5.2.x only interfaces can have them."

I believe you could make yourself in trouble when using it, and that's why there is a warning with strict.

It does make sense, because overloading is something that works on classes, and static functions do not reference classes.

answer Jun 3, 2013 by anonymous
Similar Questions
0 votes

I am trying to export certain data from my PHP form to CSV. I can echo out to screen during testing and I can also export to CSV the static test data (stored in the $contents array) you see below. But I am stuck trying to export the certain fields that I only need to export.
This is my code

// How do I get this info into the CSV?
/*foreach ( $entries as $entry ) :  
    echo $entry['2'];
    echo $entry['3'];
    echo $entry['6'];
endforeach;*/

$csv_headers = [
    'Organisation Name',
    'Registered Charity Number',
    'Address',
    'Phone',
];

$contents = [
  [2014, 6, '1st half', 'roland@fsjinvestor.com', 0, 0],
  [2014, 6, '1st half', 'steve@neocodesoftware.com', 0, 0],
  [2014, 6, '1st half', 'susanne@casamanager.com', 0, 0],
  [2014, 6, '1st half', 'tim', 0, 0]
];

fputcsv($output_handle, $csv_headers);

foreach ( $contents as $content) :
    fputcsv($output_handle, $content);
endforeach;
0 votes

I've recently discovered that a format such as %'.2f" results in this:

php -r "printf("%'.2f", 23232323.237);"
23232323.237000

I know that number_format() will do the same, but I am given the format spec as an interface, I would need to try to parse it and then decide whether to use printf() or number_format().


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...