Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

value, (stream and resource)

Posted on 2013-12-06
2
Medium Priority
?
268 Views
Last Modified: 2013-12-06
<?php
class Animal{
  public function __construct(){
    $this->created=time();
    $this->logfile_handle=fopen('log.txt','w');
  }
  public function __destruct(){
    fclose($this->logfile_handle);
  }
}

$c=new Animal();

Open in new window


Running this code in a debugger,
in the constructor
$this->logfile value=2, type=stream
in the destructor
$this->logfile value=2, type=resource

why value =2
what is the difference between stream and resource
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39701098
I'm guessing that you mean $this->logfile_handle and not $this->logfile?  Othewise we may not be looking at the right code sample.

From PHP.net:
fopen() binds a named resource, specified by filename, to a stream.

Worth reading:
http://php.net/manual/en/intro.stream.php
http://php.net/manual/en/resource.php

It's not worth overanalyzing this.  Just accept the fact that it works this way.  fopen() is called to open the file.  The function returns a resource, also called a handle, that can be used with other functions to read and write.  By naming the resource in the other function calls, your script can simultaneously read and update several files at a time.  When your logic indicates that the data access is complete, you want to use fclose().  I would avoid re-using a variable name that was a file resource; it's too easy to confuse yourself with something like that.
0
 

Author Closing Comment

by:rgb192
ID: 39701361
I think I fully understand but your advice is to accept and move on.
Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question