Solved

casting object of closure to string?

Posted on 2014-12-28
6
82 Views
Last Modified: 2014-12-29
Hello,

I have this function that returns an object, which i would like to turn into a string. Casting it returns an error. Please help?

$hehe =(string) (function() {
			echo '[';
			for ($j = 0; $j < 1; $j++) {
				echo '{';
				echo '"title":"All Day Event",';
				echo '"start":"2014-11-01",';
				echo '"end":"2014-11-01"';
				if ($j == 1-1){
			             echo '}';
			        }
               			else {
		        		echo '},';
			       	}

			}
			echo ']';
		});

Open in new window

0
Comment
[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
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40521305
Where is the object that it returns?
0
 

Author Comment

by:NeverEndingFlashStories
ID: 40521319
Well, apparently when i do gettype($hehe)
$hehe is an object.

I kind of expected it to be a string.
By the way, my casting it as a (string) at the beginning returns an error
0
 
LVL 84

Expert Comment

by:ozo
ID: 40521345
What would you want the contents of the string to be?
0
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 

Author Comment

by:NeverEndingFlashStories
ID: 40521419
Ah i am trying to produce this :

$hehe =  '[
  {
    "title": "All Day Event",
    "start": "2014-11-01"
  },
  {
    "title": "Long Event",
    "start": "2014-11-07",
    "end": "2014-11-10"
  }]'

I just realized i may have used the wrong thing when i used echo...i should have used concatenate instead, maybe? I am new to php..
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40521572
Do you mean something like this?
$f = function($t,$s,$e){
            $str=      '[
';
            for ($j = 0; $j < 2; $j++) {
                  $str .= '  {
';
                  if ($j == 2-1){
                          $str .= '    "title":"'.$t.',
    "start": "'.$s.'",
    "end": "'.$e.'
  }';
                    }
                             else {
                        $str .= '    "title":"All Day Event",
';
                               $str .= '    "start":"2014-11-01",
';
                          $str .= '  },
';
                               }

                  }
                  $str .= ']';
             return $str;
};
$hehe=$f("Long Event","2014-11-07","2014-11-10");
echo $hehe;
0
 

Author Closing Comment

by:NeverEndingFlashStories
ID: 40523094
Yes ,

precisely. Thank you so much!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

624 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