So I have this bit of code below to determine if the $this->stream is a resource. If it is not a resource then it should use fopen to create a resource, but it doesn't seem to work.
How do I make $this->stream a resource I thought fopen() was designed to open or create a file if it doesn't exist. Anything opened or created should be a resource correct? Why would I hit the code to throw an exception?
if (!is_resource($this->stream)) {
$this->errorMessage = null;
set_error_handler(array($this, 'customErrorHandler'));
$this->stream = fopen($this->url, 'a');
restore_error_handler();
if (!is_resource($this->stream)) {
$this->stream = null;
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
}
}