title: Parse files to get a specific constant and its integer to store into an array
body: <p>I have several Exception classes like this one (is PHP, but it doesnt matter right now):</p>
  
  <pre><code>class FileNotFoundException extends OtherException {
      const DEFAULT_FILE_NOT_FOUND_ERROR_CODE = 159;
  
      public function __construct($code=self::DEFAULT_FILE_NOT_FOUND_ERROR_CODE) {
              parent::__construct($code);
      }
  
  }
  </code></pre>
  
  <h1>The Problem</h1>
  
  <p>I need to get the error codes from all files to store them into an array (the index is the error code, and the value is the constant name) to just print it with order.  </p>
  
  <h2>Tips</h2>
  
  <ol>
  <li>All the files are <code>.php</code> files </li>
  <li>The constant error codes are always like <code>const DEFAULT_[A-Z_]_ERROR_CODE = [0-9]+;</code></li>
  <li>I tried to be stored in an array like this <code>array[159]="DEFAULT_FILE_NOT_FOUND_ERROR_CODE";</code></li>
  </ol>
  
  <h1>What have I done</h1>
  
  <p>What I tried to do --with my little bashscripting knowledge-- is a <strong>script</strong> that parses all this php exception files and gets only the constant <code>DEFAULT_[...]_ERROR_CODE = "number";</code> </p>
  
  <p>This is my <strong>script.sh</strong> trying to get it:  </p>
  
  <pre><code>#! /bin/bash
  
  sed -n "s/const \(DEFAULT[A-Z_]*\) = \([0-9]*\);/$array[\2]=\1;/p" $1
  </code></pre>
  
  <p>And if I do this:<br>
  <code>script.sh &lt;  FileNotFoundException.php</code>   </p>
  
  <p>It outputs <code>[159]=DEFAULT_FILE_NOT_FOUND_ERROR_CODE;</code>   </p>
  
  <p>Then I tried to put a variable "array" in there, like this:  </p>
  
  <pre><code>eval('$array(`sed -n "s/const \(DEFAULT[A-Z_]*\) = \([0-9]*\);/$array[\2]=\1;/p" $1`)')
  </code></pre>
  
  <p>and several other combinations, but with no success.  </p>
  
  <h2>Why I'm posting this in stackOverflow</h2>
  
  <p>I wanted to know if is possible to solve it and <strong>how</strong>, or if there is other way easier to do it.  </p>
  
  <p>Thanks</p>