Skip to main content
added 6 characters in body
Source Link
MonkeyZeus
  • 546
  • 3
  • 9

How to namespace global function overrides?

In PHP, trim() exists.

By default the second parameter is " \n\r\t\v\x00"

I wish to introduce my own version which doesn't deviate far from the core functionality:

// Trim whitespace in addition to what the invoker requests
function trim_also( $string, $addl_characters = '' ){
    return trim( $string, $addl_characters." \n\r\t\v\x00" );
}

Having recently expanded our Composer ecosystem, I wish to do something like:

namespace local;

class Override {
    static function trim( $string, $addl_characters = '' ) {
        return trim( $string, $addl_characters." \n\r\t\v\x00" );
    }
    
    // Assume ltrim() and rtrim() will exist
    
    // Is it okay to have htmlentities() in here as well which sets defaults different than PHP?
}

This feels acceptable:

var_dump( \local\Override::trim( 'val1|val2|val3 | ', '|' ) );
// string(14) "val1|val2|val3"

What namespace/class naming and proximity scheme would you consider acceptable for such a function?

  • \local\Override::trim()
  • \local\Strings::trim()
  • \local\Helpers::trim()
  • \local\MonkeyZeus::trim()
  • \local\MonkeyZeus\Override::trim()
  • \local\Util\Override::trim()
  • \local\TrimStuff::trim() - considering my plans for htmlentities(), I don't like this one

I feel the function is not specific to me nor any business logic nor niche use-cases and the other developers would gladly use it.

How to namespace global overrides?

In PHP, trim() exists.

By default the second parameter is " \n\r\t\v\x00"

I wish to introduce my own version which doesn't deviate far from the core functionality:

// Trim whitespace in addition to what the invoker requests
function trim_also( $string, $addl_characters = '' ){
    return trim( $string, $addl_characters." \n\r\t\v\x00" );
}

Having recently expanded our Composer ecosystem, I wish to do something like:

namespace local;

class Override {
    static function trim( $string, $addl_characters = '' ) {
        return trim( $string, $addl_characters." \n\r\t\v\x00" );
    }
    
    // Assume ltrim() and rtrim() will exist
    
    // Is it okay to have htmlentities() in here as well which sets defaults different than PHP?
}

This feels acceptable:

var_dump( \local\Override::trim( 'val1|val2|val3 | ', '|' ) );
// string(14) "val1|val2|val3"

What namespace naming and proximity scheme would you consider acceptable for such a function?

  • \local\Override::trim()
  • \local\Strings::trim()
  • \local\Helpers::trim()
  • \local\MonkeyZeus::trim()
  • \local\MonkeyZeus\Override::trim()
  • \local\Util\Override::trim()
  • \local\TrimStuff::trim() - considering my plans for htmlentities(), I don't like this one

I feel the function is not specific to me nor any business logic nor niche use-cases and the other developers would gladly use it.

How to namespace global function overrides?

In PHP, trim() exists.

By default the second parameter is " \n\r\t\v\x00"

I wish to introduce my own version which doesn't deviate far from the core functionality:

// Trim whitespace in addition to what the invoker requests
function trim_also( $string, $addl_characters = '' ){
    return trim( $string, $addl_characters." \n\r\t\v\x00" );
}

Having recently expanded our Composer ecosystem, I wish to do something like:

namespace local;

class Override {
    static function trim( $string, $addl_characters = '' ) {
        return trim( $string, $addl_characters." \n\r\t\v\x00" );
    }
    
    // Assume ltrim() and rtrim() will exist
    
    // Is it okay to have htmlentities() in here as well which sets defaults different than PHP?
}

This feels acceptable:

var_dump( \local\Override::trim( 'val1|val2|val3 | ', '|' ) );
// string(14) "val1|val2|val3"

What namespace/class naming and proximity scheme would you consider acceptable for such a function?

  • \local\Override::trim()
  • \local\Strings::trim()
  • \local\Helpers::trim()
  • \local\MonkeyZeus::trim()
  • \local\MonkeyZeus\Override::trim()
  • \local\Util\Override::trim()
  • \local\TrimStuff::trim() - considering my plans for htmlentities(), I don't like this one

I feel the function is not specific to me nor any business logic nor niche use-cases and the other developers would gladly use it.

Source Link
MonkeyZeus
  • 546
  • 3
  • 9

How to namespace global overrides?

In PHP, trim() exists.

By default the second parameter is " \n\r\t\v\x00"

I wish to introduce my own version which doesn't deviate far from the core functionality:

// Trim whitespace in addition to what the invoker requests
function trim_also( $string, $addl_characters = '' ){
    return trim( $string, $addl_characters." \n\r\t\v\x00" );
}

Having recently expanded our Composer ecosystem, I wish to do something like:

namespace local;

class Override {
    static function trim( $string, $addl_characters = '' ) {
        return trim( $string, $addl_characters." \n\r\t\v\x00" );
    }
    
    // Assume ltrim() and rtrim() will exist
    
    // Is it okay to have htmlentities() in here as well which sets defaults different than PHP?
}

This feels acceptable:

var_dump( \local\Override::trim( 'val1|val2|val3 | ', '|' ) );
// string(14) "val1|val2|val3"

What namespace naming and proximity scheme would you consider acceptable for such a function?

  • \local\Override::trim()
  • \local\Strings::trim()
  • \local\Helpers::trim()
  • \local\MonkeyZeus::trim()
  • \local\MonkeyZeus\Override::trim()
  • \local\Util\Override::trim()
  • \local\TrimStuff::trim() - considering my plans for htmlentities(), I don't like this one

I feel the function is not specific to me nor any business logic nor niche use-cases and the other developers would gladly use it.