Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be a good noop for PhP

Tags:

php

noop

no-op

Sometimes I do not want to do anything.

I just want to have a statement so I can put break point.

In c and objective-c we have while (false);

Say I want to break a function

-(void)viewDidAppear:(BOOL)animated
{

    [super viewDidAppear:animated];
    self.navigationItem.leftBarButtonItem=nil;
    self.navigationItem.rightBarButtonItem=nil;


    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateDisplays) name: NotificationUpdateArroworLocation object:nil];

    PO(self.tableView.indexPathForSelectedRow);
    while(false);//I put break point here so program stop here.
}

In .net we have donothing (Not sure Did I make that up?).

What should we use in PhP?

like image 764
user4234 Avatar asked Jan 09 '13 09:01

user4234


2 Answers

You can use same trick and a lot of other features:

<?php
    while (false);
    // or empty output
    echo '';
    // or any expression without side effects
    5 + 5;

If you use XDebug, you can call xdebug_break() function directly in any place.

like image 85
Alex Avatar answered Oct 22 '22 22:10

Alex


Would

assert(true);

be enough to attach a breakpoint to?

For the dev environment, assertions should be compiled and executed. For the prod environment, assertions should probably not be compiled nor executed. So you can leave them in. Which is useful!

http://www.php.net/manual/en/function.assert.php

like image 11
Richard A Quadling Avatar answered Oct 22 '22 21:10

Richard A Quadling