---
title: "Using the Slice Compiler"
url: https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler
language: php
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Using the Slice Compiler

Programming language: PHP. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/matlab.md), [Python](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/swift.md).

## Common Options

Ice provides a Slice compiler for each language mapping. The compilers share a similar command-line syntax:

```shell
slice2<name> [options] file...
```

Regardless of which compiler you use, a number of command-line options are common to the compilers for any language mapping:

- `-h, --help` Displays a help message.
- `-v, --version` Displays the compiler version.
- `-DNAME` Defines the preprocessor symbol `NAME` with the value `1`.
- `-DNAME=DEF` Defines the preprocessor symbol `NAME` with the value `DEF`.
- `-UNAME` Undefines the preprocessor symbol `NAME`.
- `-IDIR` Add the directory `DIR` to the search path for `#include` directives.
- `--output-dir` `DIR` Place the generated files into directory `DIR`, which must already exist.
- `-d, --debug` Print debug information showing the operation of the Slice parser.

The following options print dependency information:

- `--depend` Print dependency information in Makefile format to standard output by default, or to the file specified by the `--depend-file` option.
- `--depend-xml` Print dependency information in XML format to standard output by default, or to the file specified by the `--depend-file` option.
- `--depend-file FILE` Directs dependency information to the specified file. The output format depends on whether `--depend` or `--depend-xml` is specified.

With these options, the compiler prints the complete list of Slice files that the input Slice files depend on, through direct or indirect inclusion, and generates no code.

The Slice compilers permit you to compile more than a single source file, so you can compile several Slice definitions at once, for example:

```shell
slice2cpp -I. file1.ice file2.ice file3.ice
```

Each compiler predefines macros that identify the compiler and the Ice version; see [Conditional Compilation](https://docs.zeroc.com/ice/3.8/slice/slice-source-files.md#conditional-compilation).

## The Slice Compiler for PHP

The Slice-to-PHP compiler (`slice2php`) offers one additional option:

- `--all` Generate code for all Slice definitions, including those from included files.

### Compiler Output

For each Slice file `X.ice`, `slice2php` generates PHP code into a file named `X.php` in the output directory. The default output directory is the current working directory, but a different directory can be specified using the `--output-dir` option.

### Include Files

Without the `--all` option, the compiler generates no code for Slice definitions in included files. Instead, it translates each `#include` directive into a `require_once` statement for the PHP file generated from the included file, and places these statements in a global `namespace` block.

Each `require_once` statement uses the shortest of these paths: the path from the `#include` directive, and the path of the included file relative to each include directory (specified with `-I`) that contains it. For example, if `/opt/App/slice/Main.ice` contains `#include <Process.ice>` and you specify `-I/opt/App/slice/OS` and `-I/opt/App/slice`, the compiler generates:

```php
namespace
{
    require_once 'Process.php';
}
```

If `Main.ice` contains `#include "OS/Process.ice"` instead, the compiler generates `require_once 'OS/Process.php';` even with `-I/opt/App`, because `OS/Process` is shorter than `slice/OS/Process`.

## See Also

- [Slice Compilation](https://docs.zeroc.com/ice/3.8/slice/slice-compilation.md)
