Skip to content

Instantly share code, notes, and snippets.

@kimikimi714

kimikimi714/Hello.php

Last active Feb 7, 2016
Embed
What would you like to do?
How to make valid phar file? (Hello.php puts in hello directory.)
<?php
class Hello {
public function sayHello() {
echo "hello\n";
}
}
<?php
$phar = new Phar('hello.phar', 0, 'hello.phar');
$phar->buildFromDirectory(__DIR__ . '/hello');
$phar->setDefaultStub();
<?php
try {
$file = (new PharFileInfo('phar://' . __DIR__ . '/hello.phar/hello/Hello.php'))->openFile();
var_dump($file);
} catch (Exception $e) {
var_dump($e);
}
@kimikimi714

This comment has been minimized.

Copy link
Owner Author

@kimikimi714 kimikimi714 commented Jun 28, 2014

This is an output when I executed open_phar.php.

object(RuntimeException)#3 (7) {
  ["message":protected]=>
  string(118) "Cannot access phar file entry '/hello/Hello.php' in archive '/Users/kimikimi714/Documents/hello.phar'"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(59) "/Users/kimikimi714/Documents/open_test.php"
  ["line":protected]=>
  int(6)
  ["trace":"Exception":private]=>
  array(1) {
    [0]=>
    array(6) {
      ["file"]=>
      string(59) "/Users/kimikimi714/Documents/open_test.php"
      ["line"]=>
      int(6)
      ["function"]=>
      string(11) "__construct"
      ["class"]=>
      string(12) "PharFileInfo"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(1) {
        [0]=>
        string(79) "phar:///Users/kimikimi714/Documents/hello.phar/hello/Hello.php"
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
}

_人人人人人人人人人人_
> RuntimeException <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄

@DjJakkiGlass

This comment has been minimized.

Copy link

@DjJakkiGlass DjJakkiGlass commented Feb 7, 2016

I don't understand how to take the files from an updated plugin and make it into a .phar file on my server. Plz help

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