Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:38:27+00:00 2026-06-18T01:38:27+00:00

I have several Exception classes like this one (is PHP, but it doesnt matter

  • 0

I have several Exception classes like this one (is PHP, but it doesnt matter right now):

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);
    }

}

The Problem

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.

Tips

  1. All the files are .php files
  2. The constant error codes are always like const DEFAULT_[A-Z_]_ERROR_CODE = [0-9]+;
  3. I tried to be stored in an array like this array[159]="DEFAULT_FILE_NOT_FOUND_ERROR_CODE";

What have I done

What I tried to do –with my little bashscripting knowledge– is a script that parses all this php exception files and gets only the constant DEFAULT_[...]_ERROR_CODE = "number";

This is my script.sh trying to get it:

#! /bin/bash

sed -n "s/const \(DEFAULT[A-Z_]*\) = \([0-9]*\);/$array[\2]=\1;/p" $1

And if I do this:
script.sh < FileNotFoundException.php

It outputs [159]=DEFAULT_FILE_NOT_FOUND_ERROR_CODE;

Then I tried to put a variable “array” in there, like this:

eval('$array(`sed -n "s/const \(DEFAULT[A-Z_]*\) = \([0-9]*\);/$array[\2]=\1;/p" $1`)')

and several other combinations, but with no success.

Why I’m posting this in stackOverflow

I wanted to know if is possible to solve it and how, or if there is other way easier to do it.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:38:28+00:00Added an answer on June 18, 2026 at 1:38 am

    Remove the “$” in front of array:

    #! /bin/bash
    sed -n "s/.*const \(DEFAULT[A-Z_]*\) = \([0-9]*\);.*/array[\2]=\1;/p" $1
    

    Now it will output array[159]=DEFAULT_FILE_NOT_FOUND_ERROR_CODE; which can be eval’d to set array elements:

    eval "$(find yourdir -name '*.php' -exec cat {} + | yourscript)"
    

    (I also added some .*s to the sed expression so that appending a $(rm -ri /) to the line in the php script won’t cause you to evaluate it.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got several classes looking like the one below, and I need to
Let's say we have several exception classes that extends exception. My question is, in
I have several classes that are basically interfaces to database rows. Since the class
I have a class instance that is used by several other classes in other
I have a Windows 8 application. This application has several custom-defined classes. I need
I have several Entity classes. Now I want to use @PostLoad in every entity.
I have two classes: An activity class that controls several widgets and then a
So. I'm having trouble fixing this little problem. I have several classes, and it's
I have a base class with several derived classes that extend it. I want
I have seen the following exception case several times public SomeClass(IEnumerable<T> someValues) { if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.