php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55542 SNMP class should use Exceptions instead of PHP Errors
Submitted: 2011-08-30 22:15 UTC Modified: 2011-09-02 20:23 UTC
From: ch@php.net Assigned: lytboris (profile)
Status: Closed Package: SNMP related
PHP Version: 5.4.0alpha3 OS:
Private report: No CVE-ID: None
 [2011-08-30 22:15 UTC] ch@php.net
Description:
------------
Hello

Subject says all, IMHO it does not make sense to start writing a new class that does not use 100% exceptions.

This bug is a follow up on #40816 which ended with:

 [2011-08-30 15:18 UTC] lytboris@php.net

> I have read a bunch of threads on php-dev about extensions throwing exceptions and the last thing I remember that extension should not throw any exception except object creation if there is no way to disable them.

> Anyway, if to throw exceptions, library will throw an exception for each error, not only parsing error.


Please, please, convinced yourself that Exceptions are cool and worth refactoring the code. I'd be willing to help with writing tests :)

I'd be curious about the threads you mentioned (a quick google found nothing but then the keywords are very common) but there are already some extensions (spl/php_spl.c, mysql/php_mysql.c, reflection/php_reflection.c) that do throw Exceptions.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-31 08:41 UTC] lytboris@php.net
-Assigned To: +Assigned To: lytboris
 [2011-09-02 10:04 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&revision=316029
Log: added SNMPException class, enabling ability to throw exceptions
when a known SNMP error has occured
FR #55542
 [2011-09-02 10:13 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&revision=316032
Log: merge from trunk
added SNMPException class, enabling ability to throw exceptions
when a known SNMP error has occured
FR #55542
 [2011-09-02 10:13 UTC] lytboris@php.net
-Status: Assigned +Status: To be documented
 [2011-09-02 10:13 UTC] lytboris@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

A new SNMP object property is introduced: exceptions_enabled.
Setting this property to ORed combination of SNMP::ERRNO_* errors will enable exception throwing on these errors. SNMP::ERRNO_ANY may be used to enable all posslible SNMP::ERRNO_* errors at once.
 [2011-09-02 10:41 UTC] ch@php.net
-Status: To be documented +Status: Open
 [2011-09-02 10:41 UTC] ch@php.net
Thanks for implementing this so quickly. But the constructor still says: "snmp_object->exceptions_enabled = 0;", as this is a class one would rather expect OOP style exceptions as default, or?
 [2011-09-02 11:48 UTC] lytboris@php.net
enable SNMP::ERRNO_ANY by default is not a good idea I think. PDO has the same default behavior for throwing exceptions.
 [2011-09-02 12:05 UTC] ch@php.net
But PDO has a history back to PHP4 or the days where people where used to check every single return value for PEAR_Error. The SNMP class is new and could lead as good example for proper OOP style!

(Or do you prefer C style $errno checking after every method call over try/catch statements? The chances that an error goes unnoticed is much lower with exceptions.)
 [2011-09-02 18:52 UTC] lytboris@php.net
Here it is thread in PHP-DEV I mentioned:
http://marc.info/?l=php-internals&m=129853991816725
Unless something changes I would prefer to techniques described there.
 [2011-09-02 19:56 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&revision=316054
Log: documentation for SNMPException class (FR #55542)
 [2011-09-02 20:23 UTC] lytboris@php.net
-Status: Assigned +Status: Closed
 [2011-09-02 20:23 UTC] lytboris@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 09:01:29 2024 UTC