Skip to content

Conflict with PHP 8.6's IOException #363

Closed

Description

Activity

  1. added theissue type on Jun 20, 2026
  2. thekid commented on Jun 20, 2026

    @thekid
    MemberAuthor

    This occurs in quite a few places:

    $ grep -Hrn 'IOException' ~/devel/xp/core/src/main/php | wc -l
    132
    
    $ grep -Hrn 'IOException' ~/devel/xp/*/src/main/php | grep -v core | wc -l
    206
  3. thekid commented on Jun 20, 2026

    @thekid
    MemberAuthor

    We could replace io.IOException with io.IOError and use class_alias() for backwards compatibility, backporting this to XP11 and then changing all libraries to begin using io.IOError.

    See https://docs.oracle.com/en/java/javase/26/docs/api/java.base/java/io/IOError.html

  4. thekid commented on Jun 20, 2026

    @thekid
    MemberAuthor

    Alternatively, we could start naming them without Exception

    public class io.OperationFailed  // the former IOException
    public class io.NotFound         // instead of FileNotFoundException
    public class io.NotSupported     // instead of OperationNotSupportedException
    public class io.TimedOut         // instead of OperationTimedOutException
    public class io.PermissionDenied // New

    If we're changing something here with far-reaching consequences we might as well modernize even more.

  5. thekid commented on Jun 21, 2026

    @thekid
    MemberAuthor

    Libraries affected:

    $ grep -Hirn IOException ../*/src | cut -d / -f 2 | sort | uniq -c | sort -rn | grep -v core
         56 io-collections
         50 compression
         37 ftp
         31 web
         18 rdbms
         13 http
         12 imaging
         10 json
          7 mongodb
          6 aws
          5 text-encode
          5 networking
          5 mail
          3 frontend
          2 tokenize
          2 geoip
          2 compiler
          1 xml
          1 stomp
          1 rest-client
          1 openai
          1 lambda
  6. thekid commented on Jun 21, 2026

    @thekid
    MemberAuthor

    XP Basics ✅

    • xp-framework/compiler@427045f
    • xp-framework/ast- no use of I/O exceptions
    • xp-framework/test - no use of I/O exceptions
    • xp-framework/reflection - no use of I/O exceptions
  7. thekid commented on Jun 21, 2026

    @thekid
    MemberAuthor

    Here's a typical library diff:

    • Bump dependencies to XP 12.11 / XP 11.11, both of which contain the refactoring, drop XP 10 (!)
    • While we're at it, check if a subclass of io.OperationFailed is better suited (here, it is!)
    diff --git a/composer.json b/composer.json
    index a6cc9e4..72618c9 100755
    --- a/composer.json
    +++ b/composer.json
    @@ -6,7 +6,7 @@
       "description" : "Reads and writes JSON to and from various input sources",
       "keywords": ["module", "xp"],
       "require" : {
    -    "xp-framework/core": "^12.0 | ^11.0 | ^10.0",
    +    "xp-framework/core": "^12.11 | ^11.11",
         "php" : ">=7.4.0"
       },
       "require-dev" : {
    diff --git a/src/main/php/text/json/MultiByteSource.class.php b/src/main/php/text/json/MultiByteSource.class.php
    index ac2bfbd..fd89975 100755
    --- a/src/main/php/text/json/MultiByteSource.class.php
    +++ b/src/main/php/text/json/MultiByteSource.class.php
    @@ -1,6 +1,6 @@
     <?php namespace text\json;
     
    -use io\IOException;
    +use io\NotSupported;
     use io\streams\{InputStream, Seekable, Streams};
     
     class MultiByteSource implements InputStream, Seekable {
    @@ -39,7 +39,7 @@ class MultiByteSource implements InputStream, Seekable {
         if ($this->in instanceof Seekable) {
           $this->in->seek($offset, $whence);
         } else {
    -      throw new IOException('Cannot seek '.$this->in->toString());
    +      throw new NotSupported('Cannot seek '.$this->in->toString());
         }
       }
     
    diff --git a/src/main/php/text/json/StreamInput.class.php b/src/main/php/text/json/StreamInput.class.php
    index b9d54f4..51b7374 100755
    --- a/src/main/php/text/json/StreamInput.class.php
    +++ b/src/main/php/text/json/StreamInput.class.php
    @@ -1,6 +1,6 @@
     <?php namespace text\json;
     
    -use io\IOException;
    +use io\NotSupported;
     use io\streams\{InputStream, Seekable};
     use lang\FormatException;
     
    @@ -79,7 +79,7 @@ class StreamInput extends Input {
        * Resets input
        *
        * @return void
    -   * @throws io.IOException If this input cannot be reset
    +   * @throws io.NotSupported If this input cannot be reset
        */
       public function reset() {
         if ($this->in instanceof Seekable) {
    @@ -89,7 +89,7 @@ class StreamInput extends Input {
           $this->pos= 0;
           $this->firstToken= null;
         } else {
    -      throw new IOException('Cannot seek streams of type '.typeof($this->in)->getName());
    +      throw new NotSupported('Cannot seek streams of type '.typeof($this->in)->getName());
         }
       }
     
    diff --git a/src/test/php/text/json/unittest/StreamInputTest.class.php b/src/test/php/text/json/unittest/StreamInputTest.class.php
    index 9a3de36..4f30a5b 100755
    --- a/src/test/php/text/json/unittest/StreamInputTest.class.php
    +++ b/src/test/php/text/json/unittest/StreamInputTest.class.php
    @@ -1,6 +1,6 @@
     <?php namespace text\json\unittest;
     
    -use io\IOException;
    +use io\NotSupported;
     use io\streams\{InputStream, MemoryInputStream};
     use test\{Assert, Test, Values};
     use text\json\StreamInput;
    @@ -76,7 +76,7 @@ class StreamInputTest extends JsonInputTest {
           public function close() { }
         });
         Assert::equals([1], iterator_to_array($input->elements()), '#1');
    -    Assert::throws(IOException::class, function() use($input) {
    +    Assert::throws(NotSupported::class, function() use($input) {
           $input->reset();
           iterator_to_array($input->elements());
         });
    
  8. thekid commented on Jun 21, 2026

    @thekid
    MemberAuthor

    What's left:

    $  grep -Hirn IOException ../*/src | cut -d / -f 2 | sort | uniq -c | sort -rn | grep -v core
         56 io-collections
         18 rdbms
          5 text-encode
          5 mail
          1 stomp
  9. thekid commented on Jun 21, 2026

    @thekid
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions