there is a class

class Article { var $id; var $title; var $content; function __construct($id, $title, $content) { $this->id = $id; $this->title = $title; $this->content = $content; } } 

Can I specify a picture as a field? I guessed it only up

 $articleImage = new Article('7', 'Первый экземпляр с картинкой', '<img src="img/9467.jpg" alt="">'); 

but can it be better? not much to kick, just learning.

  • 3
    What does the PLO? - Trymount
  • I thought that classes is OOP? is not it so? - Dmitriy
  • I repeat, I'm just learning. Maybe something I do not understand - Dmitri
  • one
    @Dmitry, you pass a regular line with HTML markup, not a picture. - neluzhin
  • And how to transfer the picture? - Dmitriy

1 answer 1

Fields (properties) of a class are, in fact, ordinary variables, with only nuances in terms of scope.

If you suddenly know how to "assign a picture to a variable", then with the class properties your method will work the same way. It was a lyrical digression.

Now about the "picture". “Picture”, in this context, is an ooooooooooooooochen broad concept by which almost anything can be understood, for example:

  • A set of bytes representing the image in bmp format.
  • .... jpg

... and there are hundreds of raster formats ...

  • Maybe this SVG vector image

... send vector formats ...

  • Or is it just the name of the image file on the local filesystem?
  • Relative URL to the site
  • URL to another site
  • Or is it generally ASCII graphics?

etc.

If viewed from the point of view of PHP, then two options for use are most likely and common:

  • Output the finished image to the user in the browser. This is 99.9% of the cases of working with images in PHP.
  • Image processing in terms of graphic information. Crop, format conversion, normalization, rotation, the imposition of effects and ... in general photoshop. This is 0.09%.
  • Well, another 0.01% for hellish exoticism

For the first, most common case, the "picture field" is a string variable containing a link to an image that will already be used when generating HTML.

For the second case, the "picture field" should provide access to the graphic information itself. PHP has a number of extensions for this.