5 Replies - 786 Views - Last Post: 12 February 2017 - 04:47 PM

#1 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

PHP-FIG PSRs... do you use them?

Posted 08 February 2017 - 07:25 PM

There's a group called PHP-FIG (PHP Framework Integration Group) who work on PSRs (PHP Standards Recommendations) for things like coding standards, interfaces, etc. I can see the benefit of standards, but there is always a problem with attempting to implement non-binding standards, which is that not everyone does so.

Most of the time, people don't adhere to these sort of standards because they are blissfully unaware of them. Other times, the standards don't fit the bill for whatever reason.

As an example, I'm uncomfortable with PSR-3, which gives standards for error logging. The interface methods are emergency(), alert(), critical(), error(), warning(), notice(), info(), debug(), and log(), which all looks fine and dandy, except it's attempting to enforce a predefined set of error classifications, some with wishy washy ideas about them such as "Normal but significant events". It also smells of log4php/log4net which, while a decent logging library, shouldn't be used as a basis for dictating standards of a language.

Does anyone else here have thoughts on the PHP-FIG PSRs, and does anyone abide by them?

This post has been edited by e_i_pi: 08 February 2017 - 07:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: PHP-FIG PSRs... do you use them?

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1790
  • View blog
  • Posts: 5,705
  • Joined: 15-January 14

Re: PHP-FIG PSRs... do you use them?

Posted 09 February 2017 - 10:51 AM

I'm blissfully unaware. I'm also blissfully unaware of the difference between "emergency" and "critical".
Was This Post Helpful? 1
  • +
  • -

#3 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: PHP-FIG PSRs... do you use them?

Posted 09 February 2017 - 04:16 PM

View PostArtificialSoldier, on 10 February 2017 - 03:51 AM, said:

I'm blissfully unaware. I'm also blissfully unaware of the difference between "emergency" and "critical".

Which is exactly what I mean, it's an attempt to impose phrasing on a language that a) is open to interpretation, and b] can't be enforced in any way.

I don't want to call it a circle jerk, but if it looks like a circle jerk, and smells like a circle jerk...

Just look at PSR-6 vs PSR-16. PSR-6 defines a Caching Interface. PSR-16 defines a Simple Cache Interface. To me, PSR-16 looks more like an array or a (.NET) collection. That's great, one of the biggest problems with PHP is the inability to declare an array of type. What I don't get though is why CacheInterface isn't called CollectionInterface, and why it doesn't extend any/all of Iterator, ArrayAccess, SeekableIterator, Serializble, or Countable, and leverage those constraints and more importantly leverage the built-in language Iterator aspect of being able to go foreach($myCache as $cachedItem).

Also, alert() doesn't mean what you think it means. The description given is "[t]his should trigger the SMS alerts and wake you up." Because, you know, you can't write a PHP application without having SMS alerts when something goes down

This post has been edited by e_i_pi: 09 February 2017 - 04:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1790
  • View blog
  • Posts: 5,705
  • Joined: 15-January 14

Re: PHP-FIG PSRs... do you use them?

Posted 09 February 2017 - 05:10 PM

Quote

Also, alert() doesn't mean what you think it means. The description given is "[t]his should trigger the SMS alerts and wake you up."

Crap, that's what I did for emergency. This stuff is over my head.

Anyway, if it smells like a circle jerk then I'm probably taking off.
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4238
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: PHP-FIG PSRs... do you use them?

Posted 10 February 2017 - 06:15 AM

The way I've always seen it, since I started using libraries like Monolog (which implement PSR-3), this interface has a lot of redundant error levels:

  • emergency, alert and critical are essentially the same thing, which is: deal with some part of the service being completely unusable, which should always alert somebody.
  • notice, info, debug and log likewise all provide the same thing: a way to note extra details during development that really should be ignored on production.


Some would probably argue that info should be logged in production, and they might have a point, but in my experience if it's worth logging it's generally at least a warning, if not an error. - Logging normal activity (user logins, record deletion, etc...) is another thing entirely in my opinion. Something I'd log in the application database for permanent storage, not in an error log file.

PHP's own error reporting includes only notice, warning and error user-level types. That, with the added critical level, is plenty to be getting along with:
  • notice being the debug tool, to be ignored completely in production.
  • warning being a recoverable error, hidden from the user but logged.
  • error being an error serious enough to be shown to users.
  • critical being a total clusterfuck that wakes up the IT people.


That is at least how I use loggers in my code. Never seen any need to use the other levels.
Was This Post Helpful? 1
  • +
  • -

#6 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: PHP-FIG PSRs... do you use them?

Posted 12 February 2017 - 04:47 PM

View PostAtli, on 10 February 2017 - 11:15 PM, said:

emergency, alert and critical are essentially the same thing, which is: deal with some part of the service being completely unusable, which should always alert somebody

I think this hits the nail on the head. If it's a disaster situation, you don't need to classify it as emergency, alert or critical, not when you have an input variable called "context" which is an array. You need to switch between sub-classifications? Pop a switch variable in your context array and switch on it in your logger.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1