Does C++ have less functions than PHP?

Go To StackoverFlow.com

1

I'm learning C++; I'm already fluent in PHP. I read up the differences between C++ and PHP. None of the articles that I read mentioned that PHP has far more built in functions than C++.

Right now, I'm trying to split a string in C++ and I found this: Split a string in C++? In PHP, I can simply do explode($delimiter,$string)

Am I missing something? Or is it true that PHP has more built-in functions that C++.

2012-04-05 18:46
by Leo Jiang
PHP and C++ are different languages. C (and, I guess C++) are lower level, and act differently. PHP is more "friendly", so yeah, you can say it has "more functions". A few of the answers in that question used a library called "boost", that adds a "split" function for strings - Rocket Hazmat 2012-04-05 18:50
PHP syntax is in some way similar to C/C++ but don't forget, PHP is interpreted "managed" language, but C/C++ is compiled language - rkosegi 2012-04-05 19:18


2

Both C++ and PHP have the concept of libraries which include new functions and classes..

A lot of the PHP functions are just simpler ways to do more complex things, for example, explode can be written using split and strpos instead.

Same thing for C++, I find that C++ is more lean in that aspect, sure sometimes you will have to write your own explode, or simply use some other library that someone else created.

As for which has more, I don't think it matters, both are extensible.

2012-04-05 18:52
by Matthew


1

PHP is to C++ as Java is to Javascript

They are completely different languages as a whole.

Yes, PHP was built with C++, this does not mean they will have the same functions.

Other languages were built with machine code which built up to PHP and C++ and other higher level languages, but this does not mean I can do: 1000101010111010011000 in PHP and mean something...

2012-04-05 18:56
by Neal
I don't think you really meant that... : - Martin James 2012-04-05 18:58
@MartinJames really meant what - Neal 2012-04-05 18:58
hehe...looks like we both went for metaphor. Sorry I hadn't seen your message before I hit send on mine - user590028 2012-04-05 19:02


1

C++ is closer to assembly language. And while there are thousands of functions part of the std library (and std++ library), it's not surprising you feel there are more libraries in a interpreted language such as PHP (which is written in C/C++).

C and C++ each seek to provide minimal interference between the programmer and the underlying machine (while still mainlining a semblance of portability). The creation of libraries is therefore left up to the programmer to implement to suit their task at hand. While this creates more effort on your part, the resulting code can be incredibly efficient and yield impressive performance enhancements.

Of course it's up to you to decide if the performance gains are worth the tradeoffs of increased effort.

Best of luck with your study.

2012-04-05 19:01
by user590028
Stealing my analogies are you? :- - Neal 2012-04-05 19:02
hehe...I just removed it after I saw yours came out before mine - user590028 2012-04-05 19:03
Haha no, its fine for you to have one, just cool that we both thought of the same idea ^_ - Neal 2012-04-05 19:04


0

Part of C++'s beauty lies in the fact that it is basic and does not have built in functions polluting your namespace.

Many of the functions/objects/algos that are built into other languages are part of C++'s Standard Template Library (STL). The STL is part of the core language spec, but to use the functions you need to include the proper headers.

If you want to learn C++ you should make yourself familiar with the STL and the Boost libraries.

2012-04-05 19:01
by Colin D


0

Just because C++ doesn't have a particular function that PHP has doesn't imply that C++ has a smaller standard library overall. I'd guess that the C++ standard library also has many functions that PHP does not have. For example PHP doesn't have compile-time rational arithmetic in its standard library.

I don't know which language has a larger standard library. You'll just have to get the documentation for each language and count the number of functions.

2012-04-05 19:29
by bames53


0

Does C++ have less functions than PHP?

PHP and C++ have equally the same amount of functions: One function construct which can express a certain large amount of total functions. It's probably easier in C++ to raise the number of functions that are possible more easily than in would be in PHP in case you hit this limit some time in the future.

Am I missing something? Or is it true that PHP has more built-in functions that C++.

I'm no C++ expert, but I'm pretty sure that in terms of built-in functions PHP has "more" than C++ but you can't compare it that way because the languages are too different. While it's wise in C / C++ to not have many build-in functions by default, it's the opposite in PHP as it is a scripting language that lies there to be used so it was stuffed with functions over the years.

Or to formulate it this way: You use C++ as a language to produce those functions that are compiled later on as a PHP-binding (extension) which are then available as long as you load the extension in PHP. But you will never do it the other way round.

2012-04-05 21:35
by hakre
Ads