user1032531
user1032531

Reputation: 26321

zip_open() versus ZipArchive::open

http://php.net/manual/en/ziparchive.open.php and http://php.net/manual/en/function.zip-open.php seem to do the same thing. Am I missing something? When should one be used over the other?

Upvotes: 0

Views: 1098

Answers (2)

AndrewR
AndrewR

Reputation: 6758

One is procedural and one is object-oriented, but there are some differences. Look at the return types for each. Also, zip_open() is available in PHP 4, where the ZipArchive::open() is only available in PHP 5.

I'd probably use the object-oriented ZipArchive in most cases.

Upvotes: 2

Jonathan Kuhn
Jonathan Kuhn

Reputation: 15311

If you read the manual page, the description says the differences:

http://php.net/manual/en/function.zip-open.php:

Opens a new zip archive for reading.


http://php.net/manual/en/ziparchive.open.php:

Opens a new zip archive for reading, writing or modifying.


Also, there are several options in PHP are have both a procedural (functions) and object oriented (classes) options. The classes are also not compatible with older versions of PHP. Typically object oriented should be used if available as that is the style more stuff is going in PHP. It offers more flexibility and future compatibility. The functions are typically only around still for legacy applications and to not break backwards compatibility in old scripts. However, in some cases such as MySQL, they have been deprecated.

Upvotes: 2

Related Questions