Jump to content

String class for PHP


SparK_BR

Recommended Posts

Hi, I'm new here

 

my father (and co-worker) told me to interact with a few communities that it would be good for my professional carreer.

However I can't just come here and take whatever I want, so I offer you guys this piece of code.

 

*attached*

 

Sorry for the autodoc comments in portuguese, I'm from Brasil.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/239355-string-class-for-php/
Share on other sites

so uhh... what do you think of the class?

useful, unuseful? something I forgot to do?

feedback is what keeps me working

 

and don't worry, I don't like to use code people give me. I need to read, understand and then adapt a solution to my problem :)

You do no error-checking like:

 

public function charAt($index){
  return new String(substr($this->value,$index,1));
}

 

If I pass in $index >= $str->length() it returns false, resulting in:

 

return new String(false);

 

Not all methods are fully implemented:

 

public function split($delimiter,$limit=false){
		$limit = $limit ? $limit : strlen($this->value);
		$primitive = explode($delimiter,$this->value,$limit);
		$list = array();
		foreach($primitive as $str){

		}
	}

Thank you!

 

@the first note:

new String(false) is ""

it will concat false to the empty value and return empty, which you can eval as false

 

@the second note:

now it got fixed

I remember trying to use my List class there (the same as using array but as class methods and not language functions) but then I wanted the classes not to depend on eachother and forgot to write the 2 missing lines.

 

*attached new file*

 

ps: for some reason I can't modify the first post to upload the new file there too

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.