---
title: "Usage"
description: "How to parse a command line, and the public methods of the parser."
version: "2.0"
---

> Documentation Index
> Fetch the complete documentation index at: https://cop.phalcon.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage

```php
use Phalcon\Cop\Parser;

$parser = new Parser();

// Parse params from the $argv
$params = $parser->parse($argv);

// Parse params from the $_SERVER['argv']
$params = $parser->parse();

// After parsing input, Parser provides a way to get booleans:
$parser->getBoolean('foo');

// Get param `foo` or return TRUE as a default value
$parser->getBoolean('foo', true);
```

## Methods

- `get(int|string $key, mixed $default = null): mixed`: the value of `$key` in the result of the last `parse()`, or `$default` when the result has no `$key`.
- `getBoolean(string $key, bool $default = false): bool`: the value of `$key` as a boolean. An option with no value gives `true`; `y`, `yes`, `true`, `1` and `on` give `true`; `n`, `no`, `false`, `0` and `off` give `false`. A missing key or another value gives `$default`.
- `getParsedCommands(): array`: the result of the last `parse()`.
- `has(int|string $key): bool`: `true` when the result of the last `parse()` has `$key`.
- `parse(array $argv = []): array`: parses `$argv` (`$_SERVER['argv']` when `$argv` is empty) without its first item, the script name, and returns the options and the arguments.

Source: https://cop.phalcon.io/2.0/usage/index.mdx
