Think C#, make PHP

Using PHP data structures in C#

Php is full of functions that returns various data structures sometimes quite complicated and not easy to remember. One of most weird structures is return value of getimagesize. It is an array containing values indexed by both integer and string indices.

Assume output of some example code:

We can expect output like this:

array (size=7)
0 => int 3456
1 => int 2592
2 => int 2
3 => string ’width=”3456″ height=”2592″’ (length=26)
'bits’ => int 8
'channels’ => int 3
'mime’ => string ’image/jpeg’ (length=10)

Following PHP manual we know that index 0 and 1 contains respectively the width and the height of the image. Index 2 is value indicating the type of the image and so on.

Let’s start dreaming about more comfortable way to access image properties. Lang.Php.Graph namespace contains class ImageInfo.

Note that class is decorated with AsArrayAttribute so it will not been converted to normal PHP class. Array will be used instead.

Fields are decorated with ScriptNameAttribute so every C# expression using field of ImageInfo class is converted into PHP array access expression.
For example:

Is converted to

What about image type? On PHP side we have integer value. Value 2 (or IMAGETYPE_JPEG constant) indicates Jpeg.
On C# side we have Lang.Php.Graph.ImageTypes enum. Source:

can be translated to:



Installed with WPInstant