[ class tree: System ] [ index: System ] [ all elements ]

Class: System

Source Location: /PEAR-1.10.1/System.php

Class Overview

System offers cross plattform compatible system functions



  • Release: 1.10.1


  • 1997-2006 The PHP Group


Inherited Variables

Inherited Methods

Class Details

[line 58]
System offers cross plattform compatible system functions

Static functions for different operations. Should work under Unix and Windows. The names and usage has been taken from its respectively GNU commands. The functions will return (bool) false on error and will trigger the error with the PHP trigger_error() function (you can silence the error by prefixing a '@' sign after the function call, but this is not recommended practice. Instead use an error handler with

Documentation on this class you can find in:

Example usage: if (!@System::rm('-r file1 dir1')) { print "could not delete file1 or dir1"; }

In case you need to to pass file names with spaces, pass the params as an array:

System::rm(array('-r', $file1, $dir1));

[ Top ]

Method Detail

cat   [line 323]

boolean &cat( string $args)

Concatenate files

Usage: 1) $var = System::cat('sample.txt test.txt'); 2) System::cat('sample.txt test.txt > final.txt'); 3) System::cat('sample.txt test.txt >> final.txt');

Note: as the class use fopen, urls should work also (test that)

  • Return: true on success
  • Access: public


string   $args   —  the arguments

[ Top ]

find   [line 560]

array find( mixed $args)

The "find" command


System::find($dir); System::find("$dir -type d"); System::find("$dir -type f"); System::find("$dir -name *.php"); System::find("$dir -name *.php -name *.htm*"); System::find("$dir -maxdepth 1");

Params implmented: $dir -> Start the search at this directory -type d -> return only directories -type f -> return only files -maxdepth <n> -> max depth of recursion -name <pattern> -> search pattern (bash style). Multiple -name param allowed

  • Return: Array of found files
  • Access: public


mixed   $args   —  Either array or string with the command line

[ Top ]

mkDir   [line 254]

bool mkDir( string $args)

Make directories.

The -p option will create parent directories

  • Return: True for success
  • Access: public


string   $args   —  the name of the director(y|ies) to create

[ Top ]

mktemp   [line 395]

mixed mktemp( [string $args = null])

Creates temporary files or directories. This function will remove the created files when the scripts finish its execution.

Usage: 1) $tempfile = System::mktemp("prefix"); 2) $tempdir = System::mktemp("-d prefix"); 3) $tempfile = System::mktemp(); 4) $tempfile = System::mktemp("-t /var/tmp prefix");

prefix -> The string that will be prepended to the temp name (defaults to "tmp"). -d -> A temporary dir will be created instead of a file. -t -> The target dir where the temporary (file|dir) will be created. If this param is missing by default the env vars TMP on Windows or TMPDIR in Unix will be used. If these vars are also missing c:\windows\temp or /tmp will be used.

  • Return: the full path of the created (file|dir) or false
  • See: System::tmpdir()
  • Access: public


string   $args   —  The arguments

[ Top ]

raiseError   [line 109]

bool raiseError( mixed $error)

Output errors with PHP trigger_error(). You can silence the errors with prefixing a "@" sign to the function call: @System::mkdir(..);
  • Return: false
  • Access: protected


mixed   $error   —  a PEAR error or a string with the error message

[ Top ]

rm   [line 210]

mixed rm( string $args)

The rm command for removing files.

Supports multiple files and dirs and also recursive deletes

  • Return: PEAR_Error or true for success
  • Access: public


string   $args   —  the arguments for rm

[ Top ]

tmpdir   [line 463]

string tmpdir( )

Get the path of the temporal directory set in the system by looking in its environments variables.

Note: php.ini-recommended removes the "E" from the variables_order setting, making unavaible the $_ENV array, that s why we do tests with _ENV

  • Return: The temporary directory on the system
  • Access: public

[ Top ]

which   [line 495]

mixed which( string $program, [mixed $fallback = false])

The "which" command (show the full path of a command)
  • Return: A string with the full path or false if not found
  • Author: Stig Bakken <>
  • Access: public


string   $program   —  The command to search for
mixed   $fallback   —  Value to return if $program is not found

[ Top ]

_dirToStruct   [line 141]

array _dirToStruct( string $sPath, integer $maxinst, [integer $aktinst = 0], [bool $silent = false])

Creates a nested array representing the structure of a directory

System::_dirToStruct('dir1', 0) => Array ( [dirs] => Array ( [0] => dir1 )

[files] => Array ( [0] => dir1/file2 [1] => dir1/file3 ) )

  • Return: the structure of the dir
  • Access: protected


string   $sPath   —  Name of the directory
integer   $maxinst   —  max. deep of the lookup
integer   $aktinst   —  starting deep of the lookup
bool   $silent   —  if true, do not emit errors.

[ Top ]

_multipleToStruct   [line 184]

array _multipleToStruct( array $files)

Creates a nested array representing the structure of a directory and files


array   $files   —  Array listing files and dirs

[ Top ]

_parseArgs   [line 68]

array _parseArgs( string $argv, string $short_options, [string $long_options = null])

returns the commandline arguments of a function
  • Return: the given options and there values
  • Access: public


string   $argv   —  the commandline
string   $short_options   —  the allowed option short-tags
string   $long_options   —  the allowed option long-tags

[ Top ]

_removeTmpFiles   [line 445]

void _removeTmpFiles( )

Remove temporary files created my mkTemp. This function is executed

at script shutdown time

  • Access: public

[ Top ]

Documentation generated on Sat, 17 Oct 2015 11:30:32 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.