php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53509 Incorrect Phar Example; Confusing Results
Submitted: 2010-12-09 16:14 UTC Modified: 2010-12-20 03:24 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: royanee at yahoo dot com Assigned: kalle (profile)
Status: Closed Package: PHAR related
PHP Version: 5.3.3 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: royanee at yahoo dot com
New email:
PHP Version: OS:

 

 [2010-12-09 16:14 UTC] royanee at yahoo dot com
Description:
------------
---
From manual page: http://www.php.net/phardata.copy#Examples
---
The output of the top half of the example claims to be "hi", but the output is actually "phar:///path/to/myphar.tar/b"

What is the way with the least overhead to pull a file's content out of a PharData? I was hoping to be able to access the file content through the ArrayAccess, but so far only file_get_contents and readfile have worked. Thanks.

Test script:
---------------
<?php
try {
    $phar = new PharData('myphar.tar');
    $phar['a'] = 'hi';
    $phar->copy('a', 'b');
    echo $phar['b']; // outputs "hi"
} catch (Exception $e) {
    // handle error
}

Expected result:
----------------
hi

Actual result:
--------------
phar:///path/to/myphar.tar/b

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 03:19 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=306484
Log: Fixed bug #53509 (Incorrect Phar Example; Confusing Results)
 [2010-12-20 03:24 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2010-12-20 03:24 UTC] kalle@php.net
It is excepted that the ArrayAccess returns the path to the file rather than its contents (as Phar::offsetGet() which is inherited does).

Phar provides a class named PharFileInfo that can be used to fetch the file contents, but you have to read it line by line (see: http://dk.php.net/manual/en/pharfileinfo.construct.php), so using the filesystem functions would be more simplified.

I corrected the example for what it outputs.
 [2020-02-07 06:08 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=58b6214d57e334492e39a9d28085ae62aadd0eb2
Log: Fixed bug #53509 (Incorrect Phar Example; Confusing Results)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 16:02:26 2025 UTC